encodeAesGcm function

Map<String, dynamic> encodeAesGcm(
  1. SharedKey256 deriveSharedKey(
    1. dynamic,
    2. PublicKey
    ),
  2. dynamic keyPair,
  3. PublicKey recipientPublicKey,
  4. Uint8List message, [
  5. Uint8List? iv,
])

Implementation

Map<String, dynamic> encodeAesGcm(
    ct.SharedKey256 Function(dynamic, ct.PublicKey) deriveSharedKey,
    dynamic keyPair,
    ct.PublicKey recipientPublicKey,
    Uint8List message,
    [Uint8List? iv]) {
  final sharedKey = deriveSharedKey(keyPair, recipientPublicKey);
  final cipher = AesGcmCipher(Uint8List.fromList(sharedKey.bytes));

  var initializationVector = iv ?? tweet_nacl.TweetNaCl.randombytes(12);
  final secretBox = cipher.encrypt(message, initializationVector);

  return {
    'tag': secretBox.sublist(secretBox.length - 16),
    'initializationVector': initializationVector,
    'cipherText': secretBox.sublist(0, secretBox.length - 16)
  };
}