GenerateBlake3Hash()
Generates a Blake3 hash — the fastest general-purpose hash function available, and the recommended choice for checksums and data integrity.
Supports variable output length and both keyed hashing (MAC) and key derivation modes.
Requires Extension: Crypto Extension
GenerateBlake3Hash( input=any, outputLength=numeric, key=any, context=string );
Returns: String
| Argument | Description |
|---|---|
|
input
any,
required
|
edit
Data to hash (string or binary) |
|
outputLength
numeric,
optional
|
edit
Output length in bytes (any length, default 32) |
|
key
any,
optional
|
edit
Key for keyed hash mode (MAC), must be exactly 32 bytes |
|
context
string,
optional
|
edit
Context string for key derivation mode |
Examples
edit// Blake3 is the latest in the Blake family - faster than Blake2 and SHA-256
// Default output is 32 bytes (256-bit)
hash = GenerateBlake3Hash( "hello world" );
// Blake3 is an extendable-output function (XOF) - you can request any output length
// Shorter output is always a prefix of longer output
hash32 = GenerateBlake3Hash( "test", 32 ); // 32 bytes
hash64 = GenerateBlake3Hash( "test", 64 ); // 64 bytes - starts with hash32
hash128 = GenerateBlake3Hash( "test", 128 ); // 128 bytes
// Keyed mode for MAC (requires exactly 32-byte key)
key = "12345678901234567890123456789012"; // exactly 32 bytes
mac = GenerateBlake3Hash( "important data", 32, key );
// Key derivation mode: derive different keys from the same secret using context strings
// This is useful when you need separate keys for encryption and authentication
encKey = GenerateBlake3Hash( "master-secret", 32, "", "MyApp v1 encryption" );
authKey = GenerateBlake3Hash( "master-secret", 32, "", "MyApp v1 authentication" );
// encKey != authKey - different context strings produce different keys
// Binary input is also supported
binary = charsetDecode( "hello", "utf-8" );
hash = GenerateBlake3Hash( binary );
See also
- Cryptography
- GenerateBlake2bHash()
- GenerateBlake2sHash()
- Hash()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)