importRawKey static method
Import an AesCbcSecretKey
from raw keyData
.
KeyData must be either:
- 16 bytes (128 bit) for AES-128, or,
- 32 bytes (256 bit) for AES-256.
Support for AES-192 (24 byte keys) is intentionally omitted, in line with the decision not support AES-192 in Chrome.
Example
import 'dart:convert' show utf8;
import 'dart:typed_data' show Uint8List;
import 'package:webcrypto/webcrypto.dart';
final rawKey = Uint8List(16);
fillRandomBytes(rawKey);
final k = await AesCbcSecretKey.importRawKey(rawKey);
// Use a unique IV for each message.
final iv = Uint8List(16);
fillRandomBytes(iv);
// Encrypt a message
final c = await k.encryptBytes(utf8.encode('hello world'), iv);
print(utf8.decode(await k.decryptBytes(c, iv))); // hello world
Implementation
static Future<AesCbcSecretKey> importRawKey(List<int> keyData) {
return impl.aesCbc_importRawKey(keyData);
}