hash
Package hash provides cryptographic hash SQL functions.
Functions
Section titled “Functions”- md4(data)
- md5(data)
- sha1(data)
- sha3(data, size) — size: 224, 256 (default), 384, 512
- sha224(data)
- sha256(data, size) — size: 224, 256 (default)
- sha384(data)
- sha512(data, size) — size: 224, 256, 384, 512 (default)
- blake2s(data)
- blake2b(data, size) — size: 256, 384, 512 (default)
- blake3(data, size) — size in BYTES (default 32); extendable output
- xxh64(data) — XXH64, 8-byte big-endian (fast, non-cryptographic)
- ripemd160(data)
Each SQL function is registered only when the corresponding crypto.Hash is available — registration is gated on crypto.Hash.Available(), which is true only when the implementing package has been imported. To make a function available, side-effect- import its package:
import ( _ "crypto/md5" _ "crypto/sha1" _ "crypto/sha256" _ "crypto/sha512" _ "golang.org/x/crypto/blake2b" _ "golang.org/x/crypto/ripemd160")Ported from ncruces/ext/hash.
import ( sqlite "gosqlite.org" "gosqlite.org/ext/hash")
if err := hash.Register(conn); err != nil { ... }row := db.QueryRow(`SELECT lower(hex(sha256('hello')))`)For pool-wide install via gosqlite.org.Driver.ConnectHook, blank-import the auto sub-package (which also blank-imports every supported hash algorithm so all functions register):
import _ "gosqlite.org/ext/hash/auto"Full API: pkg.go.dev/gosqlite.org/ext/hash