importJsonWebKey static method
Import an AesCtrSecretKey
from JSON Web Key.
JSON Web Keys imported using AesCtrSecretKey.importJsonWebKey
must have "kty": "oct"
, and the "alg"
property of the imported jwk
must be either:
"alg": "A128CTR"
for AES-128, or"alg": "A256CTR"
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": "A256CTR", "k": ...}';
// Import secret key from decoded JSON.
final key = await AesCtrSecretKey.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<AesCtrSecretKey> importJsonWebKey(Map<String, dynamic> jwk) {
return impl.aesCtr_importJsonWebKey(jwk);
}