Crypto DuckDB Extension

The Crypto extension, developed by Query.Farm, adds cryptographic hash functions and HMAC to DuckDB.

DuckDB extensions are plugins that expand the core DuckDB engine with new capabilities.

Getting Started

Crypto is a DuckDB community extension maintained and supported by Query.Farm.

Install Crypto in DuckDB by running:

INSTALL crypto FROM community;

Then load it with:

LOAD crypto;

Functionality

The extension provides two functions:

crypto_hash applies cryptographically secure hash functions and returns the result as a hex encoded value.

crypto_hmac calculates the HMAC using a secret key and a specific hash function.

The supported hash functions are:

  • blake2b-512
  • keccak224
  • keccak256
  • keccak384
  • keccak512
  • md4
  • md5
  • sha1
  • sha2-224
  • sha2-256
  • sha2-384
  • sha2-512
  • sha3-224
  • sha3-256
  • sha3-384
  • sha3-512

Love ❤️ this DuckDB extension? You’ll Love This.

Get the best from Query.Farm — smart tips, powerful tools, and project updates sent directly to your inbox, but only when we’ve got something great to share.

Examples

-- `Calculate the MD5 hash value of 'abcdef'`
SELECT crypto_hash('md5', 'abcdef');
┌──────────────────────────────────┐
│   crypto_hash('md5', 'abcdef')   │
varchar
├──────────────────────────────────┤
│ e80b5017098950fc58aad83c8c14978e │
└──────────────────────────────────┘

-- `Calculate a HMAC`
SELECT crypto_hmac('sha2-256', 'secret key', 'secret message');
┌──────────────────────────────────────────────────────────────────┐
│     crypto_hmac('sha2-256', 'secret key', 'secret message')      │
varchar
├──────────────────────────────────────────────────────────────────┤
2df792e08cefdc0ea9900c67c93cbe66b98231b829a5dccd3857a03baac35963 │
└──────────────────────────────────────────────────────────────────┘