ToCrypto class

Value-level encode/decode. Output is Base64 and can be stored in JSON or a TEXT column.

Use ToCryptoType for the type parameter. The key is managed by the caller; key is required and must be String or Uint8List.

Example:

final b64 = ToCrypto.encode('plain', key: key);
final plain = ToCrypto.decode(b64, key: key);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

decode(String cipherBase64, {required Object key, Uint8List? aad}) String
Decodes Base64 cipher and returns plain string.
decodeBytes(String cipherBase64, {required Object key, Uint8List? aad}) Uint8List
Decodes Base64 cipher to raw plain bytes.
decodeFromBytes(Uint8List cipherBytes, {required Object key, Uint8List? aad}) String
Decodes from raw cipher bytes (e.g. from BLOB) and returns plain string.
encode(String plainText, {required Object key, ToCryptoType type = ToCryptoType.chacha20Poly1305, Uint8List? aad}) String
Encodes a string and returns Base64.
encodeBytes(Uint8List plainBytes, {required Object key, ToCryptoType type = ToCryptoType.chacha20Poly1305, Uint8List? aad}) String
Encodes raw bytes and returns Base64.
encodeToBytes(String plainText, {required Object key, ToCryptoType type = ToCryptoType.chacha20Poly1305, Uint8List? aad}) Uint8List
Encodes to raw cipher bytes (e.g. for BLOB storage). Decode with decodeFromBytes.