Random functions in the Crypto DuckDB extension
Function category
Random
1 functionCryptographically secure random bytes from OpenSSL's CSPRNG. Use for encryption keys, salts, nonces, and any other cryptographic material that must be unpredictable.
Signature
crypto_random_bytes(length: BIGINT) → BLOB
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
length
|
Type
BIGINT
|
Mode Positional | Description |
Description
Cryptographically secure random bytes from OpenSSL's RAND_bytes. Suitable for keys, salts, nonces, and other cryptographic material. Length must be between 1 and 4 GB − 1.
1
32 random bytes — an AES-256 key
SELECT crypto_random_bytes(32);
Output
| crypto_random_bytes(32) |
|---|
| a35ef22ac875491a6cd476345f91a8daef58bfa1c417eed32a98a0d7eda7f9e9 |
2
16-byte salt displayed as hex
SELECT lower(to_hex(crypto_random_bytes(16)));
Output
| lower(to_hex(crypto_random_bytes(16))) |
|---|
| 3f8483715eda5adabf0851568cb83642 |