encrypt method

EncryptedMessage encrypt(
  1. Uint8List plainText, {
  2. Uint8List? nonce,
})

Implementation

EncryptedMessage encrypt(Uint8List plainText, {Uint8List? nonce}) {
  final nonce1 = nonce ?? TweetNaCl.randombytes(TweetNaCl.nonceLength);

  final m = Uint8List(TweetNaCl.zerobytesLength).toList() + plainText;
  final c = Uint8List(m.length);

  final cipherText = doEncrypt(c, Uint8List.fromList(m), m.length,
      Uint8List.fromList(nonce1), key.asTypedList);

  return EncryptedMessage(nonce: nonce1, cipherText: cipherText);
}