fromSecretKey static method

Future<Jwk> fromSecretKey(
  1. SecretKey secretKey, {
  2. required Cipher cipher,
})

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: 'OCK',
      alg: 'A${data.bytes.length * 8}KW',
      x: data.bytes,
    );
  }
  if (cipher is Xchacha20) {
    return Jwk(
      kty: 'OCK',
      alg: 'XC20KW',
      x: data.bytes,
    );
  }
  throw ArgumentError.value(cipher, 'cipher', 'cipher');
}