decrypt function

Future<List<int>> decrypt(
  1. B64 key,
  2. String box
)

Implementation

Future<List<int>> decrypt(B64 key, String box) {
  var parts = box.split(".");
  if (parts.length != 3) {
    throw ExInvalidCipherText;
  }
  var nonce = B64(parts[0]).decode();
  var mac = B64(parts[1]).decode();
  var text = B64(parts[2]).decode();
  return cryptography.Xchacha20.poly1305Aead().decrypt(
      cryptography.SecretBox(text.toList(),
          nonce: nonce.toList(), mac: cryptography.Mac(mac.toList())),
      secretKey: cryptography.SecretKey(key.decode().toList()));
}