DeterministicHasher class
Provides deterministic hashing for searchable fields. Unlike bcrypt, the same input always produces the same hash, making it suitable for database lookups (e.g., finding user by hashed email).
⚠️ WARNING: This is one-way hashing - you cannot decrypt the original value. For reversible encryption, use FieldEncryptor instead.
Use cases:
- Hashing emails/phone numbers for privacy while maintaining searchability
- Creating consistent identifiers from sensitive data
- Database indexing on hashed fields
Constructors
- DeterministicHasher({required String secretKey, required String salt})
-
Creates a DeterministicHasher.
secretKeymust be at least 32 characters for security.saltshould be unique per application/environment.
Properties
Methods
-
hash(
String value) → Result< String> -
Creates a deterministic hash of the input value.
The same value will always produce the same hash.
Returns Result<String> with base64-encoded hash or error.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
verify(
String value, String hash) → Result< bool> - Verifies if a value matches a hash. This is a convenience method that hashes the value and compares. Uses constant-time comparison to prevent timing attacks. Returns Result<bool> - true if value matches hash, false otherwise.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited