importRawKey static method
Import an AesGcmSecretKey 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);
// Import key from raw bytes
final k = await AesGcmSecretKey.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);
// Decrypt message (requires the same iv)
print(utf8.decode(await k.decryptBytes(c, iv))); // hello world
Implementation
static Future<AesGcmSecretKey> importRawKey(List<int> keyData) async {
final impl = await webCryptImpl.aesGcmSecretKey.importRawKey(keyData);
return AesGcmSecretKey._(impl);
}