decrypt method

Uint8List decrypt(
  1. ByteList encryptedMessage, {
  2. Uint8List? nonce,
})

Implementation

Uint8List decrypt(ByteList encryptedMessage, {Uint8List? nonce}) {
  ByteList ciphertext;
  if (encryptedMessage is EncryptedMessage) {
    nonce = encryptedMessage.nonce.asTypedList;
    ciphertext = encryptedMessage.cipherText;
  } else if (nonce != null) {
    ciphertext = encryptedMessage;
  } else {
    throw Exception('Nonce is required for a message');
  }

  final c =
      Uint8List(TweetNaCl.boxzerobytesLength).toList() + ciphertext.toList();
  final m = Uint8List(c.length);
  final plaintext =
      doDecrypt(m, Uint8List.fromList(c), c.length, nonce, key.asTypedList);
  return Uint8List.fromList(plaintext);
}