encode static method

String encode(
  1. String plainText, {
  2. required Object key,
  3. ToCryptoType type = ToCryptoType.chacha20Poly1305,
  4. Uint8List? aad,
})

Encodes a string and returns Base64.

plainText Plain text; may be empty. key Secret key, String or Uint8List (SHA-256 derived if not 32 bytes). type Encryption type, default ToCryptoType.chacha20Poly1305. aad Optional additional authenticated data; must match at decode.

Implementation

static String encode(
  String plainText, {
  required Object key,
  ToCryptoType type = ToCryptoType.chacha20Poly1305,
  Uint8List? aad,
}) {
  final plainBytes = Uint8List.fromList(utf8.encode(plainText));
  final raw = _encodeBytes(
    plainBytes,
    key: key,
    type: type,
    aad: aad,
  );
  return base64Encode(raw);
}