← all modules
module

stdlib::crypto

defined in C:\Users\bye45\.glide\bin/src/stdlib/crypto.glide

SHA-256 over `data`, returned as a 32-byte raw string. Useful when

fn fn sha256(data: string) -> string

SHA-256 over data, returned as a 32-byte raw string. Useful when you need to feed the digest into another binary protocol; for human display use sha256_hex.

**Caveat:** treats data as a NUL-terminated cstring, so embedded NUL bytes truncate the input. Hash binary blobs with embedded NULs via a future sha256_bytes(*ByteBuffer) once that's wired.

glide
let raw: string = sha256("hello");
hex_encode(raw);   // 2cf24dba...8b9824 (32 bytes)
fn fn sha256_hex(data: string) -> string

SHA-256 over data, returned as 64 lowercase hex chars. Same NUL caveat as sha256.

glide
sha256_hex("");      // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sha256_hex("abc");   // ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
fn fn hmac_sha256(key: string, msg: string) -> string

HMAC-SHA-256 with key, message msg. Returns the 32-byte raw MAC.

Same NUL caveat as sha256 — both key and msg are read until the first NUL. RFC 2104.

glide
let mac: string = hmac_sha256("secret", "payload");
hex_encode(mac);    // 32 raw bytes as hex
fn fn hmac_sha256_hex(key: string, msg: string) -> string

HMAC-SHA-256, hex-encoded.

glide
hmac_sha256_hex("key", "The quick brown fox jumps over the lazy dog");
-> f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
fn fn sha1(data: string) -> string

SHA-1 of data. Returns 20 raw bytes. **Cryptographically broken** — use only for legacy protocols that mandate SHA-1 (notably the RFC 6455 WebSocket handshake). For everything else, prefer SHA-256.

glide
let raw: string = sha1("abc");
hex_encode(raw);   // a9993e36...c9cd0d89 (20 bytes)
fn fn sha1_hex(data: string) -> string

SHA-1 of data, returned as 40 lowercase hex chars. Same caveat as sha1.

glide
sha1_hex("");      // da39a3ee5e6b4b0d3255bfef95601890afd80709
sha1_hex("abc");   // a9993e364706816aba3e25717850c26c9cd0d89d