v1.2.2 — 2026-06-07
Cryptographic primitives: base64, MD5, SHA-1, SHA-256, HMAC-SHA-256.
# Debian/Ubuntu
sudo apt install libssl-dev
# macOS (OpenSSL is keg-only; pkg-config will find it via Homebrew)
brew install opensslEnabled by -DBUILD_MODULE_CRYPTO=ON (default). Skipped silently if OpenSSL is not found.
MD5 is implemented in pure C (no OpenSSL). SHA-1, SHA-256, and HMAC use the OpenSSL EVP API.
(import (curry crypto))(base64-encode bytevector) ; → string
(base64-decode string) ; → bytevectorStandard RFC 4648 base64 with = padding.
(md5 bytevector) ; → bytevector (16 bytes)
(md5-hex bytevector) ; → string (32 lowercase hex chars)MD5 is cryptographically broken; use it only for checksums and legacy interoperability.
(sha1 bytevector) ; → bytevector (20 bytes)
(sha1-hex bytevector) ; → string (40 lowercase hex chars)SHA-1 is deprecated for security purposes. Prefer SHA-256.
(sha256 bytevector) ; → bytevector (32 bytes)
(sha256-hex bytevector) ; → string (64 lowercase hex chars)(hmac-sha256 key-bytevector message-bytevector) ; → bytevector (32 bytes)Used for AWS Signature V4, webhook verification, JWT signatures, etc.
(string->utf8 string) ; → bytevector (UTF-8 encoded)Converts a Scheme string to its UTF-8 byte representation. Use this before hashing strings.
(import (curry crypto))
; Hash a string
(sha256-hex (string->utf8 "hello world"))
; => "b94d27b9934d3e08a52e52d7da7dabfac484efe04294e576f4aee9d856e48616"
; HMAC for webhook verification
(define secret (string->utf8 "my-secret-key"))
(define payload (string->utf8 "{\"event\":\"push\"}"))
(define sig (hmac-sha256 secret payload))
(base64-encode sig) ; → base64-encoded HMAC
; AWS-style signing chain
(define (hmac-sha256-key k m)
(hmac-sha256 k (string->utf8 m)))
(define date-key (hmac-sha256-key (string->utf8 "AWS4secret") "20240101"))
(define region-key (hmac-sha256-key date-key "us-east-1"))
(define service-key (hmac-sha256-key region-key "s3"))
(define signing-key (hmac-sha256-key service-key "aws4_request"))
; Base64 encoding
(base64-encode (string->utf8 "user:password"))
; => "dXNlcjpwYXNzd29yZA=="
(define decoded (base64-decode "dXNlcjpwYXNzd29yZA=="))
; bytevector — convert back: (utf8->string decoded)- All hash functions accept bytevectors, not strings. Use
string->utf8to convert. hmac-sha256returns raw bytes (bytevector). Usebase64-encodefor HTTP headers orsha256-hexstyle — but notehmac-sha256has no-hexvariant; use(list->string (map (lambda (b) (string-ref "0123456789abcdef" (quotient b 16))) (bytevector->list sig)))or write a simple hex converter.- The storage module (
(curry storage)) uses these internally for AWS and Azure authentication.