Skip to content

DuckDB Extension

Crypto

Compute cryptographic hashes, HMACs, password hashes, derived keys, and secure random bytes in DuckDB SQL. Hash individual values or build a checksum over ordered rows.

164,995
extension loads Β· last 90 days
On this page

Compute cryptographic digests and message authentication codes

A cryptographic digest gives a piece of data a fingerprint. An HMAC combines a digest algorithm with a secret key so a recipient can check that a message came from someone holding that key and has not changed.

Crypto makes these operations available as SQL functions over your columns. Use it to compare file or record contents, create checksums, or generate the authentication value required by an integration. When reproducing a digest from another system, match its input bytes, encoding, and algorithm.

Example

Hash a string with SHA-256

The hash function returns a BLOB. Convert it to hexadecimal to display or compare the digest.

Tested with DuckDB 1.5.6. Run this example in the DuckDB CLI or a native client.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL crypto FROM query_farm;
LOAD crypto FROM query_farm;

SELECT lower(to_hex(crypto_hash('sha2-256', 'hello world'))) AS sha256;

Expected result

sha256
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

A plain hash does not authenticate a message. Use HMAC when verification depends on a shared secret; use a password-hashing library for passwords.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

HMAC
crypto_equals() Object type: Scalar function Constant-time comparison of two VARCHAR or BLOB values, using OpenSSL's CRYPTO_memcmp.
crypto_hmac() Object type: Scalar function Hash-based Message Authentication Code (HMAC).
Hashing
crypto_algorithms() Object type: Table function Lists every hash algorithm the extension knows, with its family, implementation (openssl or blake3), digest length in bytes, whether it is an extendable-output function, whether it can be used with crypto_hmac, and whether the linked OpenSSL library provides it.
crypto_hash() Object type: Scalar function Compute a cryptographic hash of a value with the given algorithm (case-insensitive).
crypto_hash_agg() Object type: Aggregate function Order-deterministic aggregate hash.
crypto_hash_xof() Object type: Scalar function Extendable-output hash: returns length bytes (1 to 4,294,967,295) of a blake3, shake128 or shake256 digest.
Key Derivation
crypto_argon2() Object type: Scalar function Argon2 password hashing (RFC 9106).
crypto_hkdf() Object type: Scalar function HKDF extract-and-expand (RFC 5869).
crypto_pbkdf2() Object type: Scalar function PBKDF2-HMAC key derivation (RFC 8018).
crypto_scrypt() Object type: Scalar function scrypt password-based key derivation (RFC 7914).
Random
crypto_random_bytes() Object type: Scalar function Cryptographically secure random bytes from OpenSSL's RAND_bytes.

API Reference

Function Reference

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
164,995
loads Β· last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 6.21 MB
Linux aarch64 5.87 MB
macOS Apple Silicon 4.64 MB
Windows x86_64 11.76 MB
Windows x86_64 (MinGW) 19.95 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .