unwrapKey method

JsonWebKey unwrapKey(
  1. List<int> data, {
  2. String? algorithm,
})

Decrypt key and validate decryption, if applicable

Implementation

JsonWebKey unwrapKey(List<int> data, {String? algorithm}) {
  _assertCanDo('unwrapKey');
  algorithm ??= this.algorithm;
  var decrypter =
      _keyPair.privateKey!.createEncrypter(_getAlgorithm(algorithm));
  var v = decrypter.decrypt(EncryptionResult(Uint8List.fromList(data)));
  return JsonWebKey.fromJson({
    'kty': 'oct',
    'k': encodeBase64EncodedBytes(v),
    'use': 'enc',
    'keyOperations': ['encrypt', 'decrypt']
  });
}