encryptAndSignCore function

Future<Map<String, String>> encryptAndSignCore({
  1. required String plainText,
  2. required List<String> keys,
  3. required String senderPgpPrivateKey,
  4. String? secretKey,
})

Implementation

Future<Map<String, String>> encryptAndSignCore({
  required String plainText,
  required List<String> keys,
  required String senderPgpPrivateKey,
  String? secretKey,
}) async {
  secretKey ??= generateRandomSecret(32);

  final cipherText =
      await aesEncrypt(plainText: plainText, secretKey: secretKey);

  final encryptedSecret = await pgpEncrypt(plainText: secretKey, keys: keys);

  final signature = await sign(
    message: cipherText,
    privateKey: senderPgpPrivateKey,
  );

  return {
    'cipherText': cipherText,
    'encryptedSecret': encryptedSecret,
    'signature': signature,
    'sigType': 'pgp',
    'encType': 'pgp',
  };
}