encrypt function

Future<String> encrypt(
  1. B64 key,
  2. List<int> blob
)

Implementation

Future<String> encrypt(B64 key, List<int> blob) async {
  var box = await cryptography.Xchacha20.poly1305Aead()
      .encrypt(blob, secretKey: cryptography.SecretKey(key.decode().toList()));
  var text = B64.encode(box.cipherText).toString();
  var mac = B64.encode(box.mac.bytes).toString();
  var nonce = B64.encode(box.nonce).toString();

  return "$nonce.$mac.$text";
}