importJsonWebKey static method
Import an AesGcmSecretKey from JSON Web Key.
JSON Web Keys imported using AesGcmSecretKey.importJsonWebKey
must have "kty": "oct", and the "alg" property of the imported jwk
must be either:
"alg": "A128GCM"for AES-128, or"alg": "A256GCM"for AES-256.
Support for AES-192 (24 byte keys) is intentionally omitted, in line with the decision not support AES-192 in Chrome.
If specified the "use" property of the imported jwk must be
"use": "sig".
Throws FormatException if jwk is invalid.
Example
import 'dart:convert' show jsonEncode, jsonDecode;
import 'package:webcrypto/webcrypto.dart';
// JSON Web Key as a string containing JSON.
final jwk = '{"kty": "oct", "alg": "A256GCM", "k": ...}';
// Import secret key from decoded JSON.
final key = await AesGcmSecretKey.importJsonWebKey(jsonDecode(jwk));
// Export the key (print it in same format as it was given).
Map<String, dynamic> keyData = await key.exportJsonWebKey();
print(jsonEncode(keyData));
Implementation
static Future<AesGcmSecretKey> importJsonWebKey(
Map<String, dynamic> jwk) async {
final impl = await webCryptImpl.aesGcmSecretKey.importJsonWebKey(jwk);
return AesGcmSecretKey._(impl);
}