fromSecretKey static method
Converts SecretKey
into Jwk
.
Implementation
static Future<Jwk> fromSecretKey(
SecretKey secretKey, {
required Cipher cipher,
}) async {
final data = await secretKey.extract();
if (cipher is AesCbc || cipher is AesCtr || cipher is AesGcm) {
return Jwk(
kty: 'OCT',
alg: 'A${data.bytes.length * 8}KW',
k: data.bytes,
);
}
if (cipher is Chacha20 &&
cipher.macAlgorithm is DartChacha20Poly1305AeadMacAlgorithm) {
return Jwk(
kty: 'OCT',
alg: 'C20PKW',
k: data.bytes,
);
}
if (cipher is Xchacha20 &&
cipher.macAlgorithm is DartChacha20Poly1305AeadMacAlgorithm) {
return Jwk(
kty: 'OCT',
alg: 'XC20KW',
k: data.bytes,
);
}
throw ArgumentError.value(cipher, 'cipher');
}