getPayloadFor method

  1. @override
List<int>? getPayloadFor(
  1. JsonWebKey? key,
  2. JoseHeader header,
  3. JoseRecipient recipient
)
override

Implementation

@override
List<int>? getPayloadFor(
  JsonWebKey? key,
  JoseHeader header,
  JoseRecipient recipient,
) {
  if (key == null) {
    return null;
  }

  var aad = sharedProtectedHeader?.toBase64EncodedString() ?? '';
  if (additionalAuthenticatedData != null) {
    aad += '.${String.fromCharCodes(additionalAuthenticatedData!)}';
  }
  if (header.encryptionAlgorithm == 'none') {
    throw JoseException('Encryption algorithm cannot be `none`');
  }
  var cek = header.algorithm == 'dir'
      ? key
      : key.unwrapKey(recipient.data, algorithm: header.algorithm);
  return cek.decrypt(data,
      initializationVector: initializationVector,
      additionalAuthenticatedData: Uint8List.fromList(aad.codeUnits),
      authenticationTag: authenticationTag,
      algorithm: header.encryptionAlgorithm);
}