chacha20Encrypt static method

String chacha20Encrypt({
  1. required String plainText,
  2. required String key,
  3. required String nonce,
  4. UByteEncoding keyEncoding = UByteEncoding.utf8,
  5. UByteEncoding nonceEncoding = UByteEncoding.utf8,
})

ChaCha20 stream cipher (no tamper check); key 32 bytes, nonce 12 bytes. chacha20Encrypt(plainText: "x", key: k, nonce: n)

Implementation

static String chacha20Encrypt({
  required String plainText,
  required String key,
  required String nonce,
  UByteEncoding keyEncoding = UByteEncoding.utf8,
  UByteEncoding nonceEncoding = UByteEncoding.utf8,
}) => base64.encode(_chacha20(_fit(_bytes(key, keyEncoding), 32), _fit(_bytes(nonce, nonceEncoding), 12), 1, _u8(plainText)));