utils/crypto/crypto_utils library
Cryptographic and encoding utilities.
Provides hashing, encoding, UUID generation, obfuscation, simple XOR encryption, and platform keychain access.
Classes
- SecureStorage
- Platform-aware secure storage using system keychains.
- XorCipher
- Simple XOR encrypt/decrypt for local storage.
Functions
-
base64Decode(
String encoded) → String - Base64-decode a string.
-
base64Encode(
String text) → String - Base64-encode a string.
-
base64UrlDecode(
String encoded) → String - URL-safe Base64 decode.
-
base64UrlEncode(
String text) → String - URL-safe Base64 encode.
-
constantTimeEquals(
String a, String b) → bool - Constant-time string comparison to prevent timing attacks.
-
generateId(
{String? prefix, int length = 12}) → String - Generate a short alphanumeric ID.
-
generateToken(
int length) → String - Generate a cryptographically random token as a hex string.
-
generateUuid(
) → String - Generate a v4 UUID.
-
hashDirectory(
String path) → Future< String> -
Compute a combined SHA-256 hash of all files in a directory at
path. -
hashFile(
String path) → Future< String> -
Compute SHA-256 hash of a file at
path. -
hmacSha256(
String key, String text) → Future< String> -
Compute HMAC-SHA256 of
textwithkey. -
md5(
String text) → Future< String> -
Compute MD5 hash of
text. -
obfuscate(
String text, {int visibleChars = 4}) → String -
Obfuscate
text, showing only the lastvisibleCharscharacters. -
redactApiKey(
String key) → String - Redact an API key, showing only the first and last few characters.
-
sha256(
String text) → Future< String> -
Compute SHA-256 hash of
text. -
sha256Sync(
String text) → String - Compute SHA-256 synchronously using Process.runSync.