simple_hash

Cryptographic Hashing for Eiffel

Features

Quick Start

Installation

Add to your ECF:

<library name="simple_hash" location="$SIMPLE_HASH\simple_hash.ecf"/>

SHA-256 Hashing

local
    hasher: SIMPLE_HASH
    digest: STRING
do
    create hasher.make

    -- Hash a string
    digest := hasher.sha256 ("Hello, World!")
    -- Result: "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f"
end

HMAC-SHA256 (for JWT, API signatures)

local
    hasher: SIMPLE_HASH
    signature: STRING
do
    create hasher.make

    -- Create keyed hash
    signature := hasher.hmac_sha256 ("secret-key", "message to sign")
    -- 64-character hex string
end

SHA-512 (Stronger security)

local
    hasher: SIMPLE_HASH
    digest: STRING
do
    create hasher.make

    -- 512-bit hash for maximum security
    digest := hasher.sha512 ("sensitive data")
    -- 128-character hex string

    -- HMAC-SHA512 for signatures
    signature := hasher.hmac_sha512 ("secret", "message")
end

File Hashing (Streaming)

local
    hasher: SIMPLE_HASH
    file_hash: detachable STRING
do
    create hasher.make

    -- Hash a file without loading it into memory
    file_hash := hasher.sha256_file ("path/to/large/file.dat")
    if attached file_hash as h then
        print ("SHA-256: " + h)
    end

    -- Also available:
    -- hasher.sha512_file (path)
    -- hasher.md5_file (path)
end

MD5 (Legacy checksums only)

local
    hasher: SIMPLE_HASH
    checksum: STRING
do
    create hasher.make

    -- WARNING: MD5 is cryptographically broken
    -- Use only for checksums, never for security
    checksum := hasher.md5 ("file contents")
end

Algorithm Comparison

Algorithm Output Size Security Use Case
SHA-256 256 bits (64 hex chars) Secure Passwords, signatures, integrity
SHA-512 512 bits (128 hex chars) Secure High-security applications
HMAC-SHA256 256 bits (64 hex chars) Secure JWT signatures, API auth, MACs
HMAC-SHA512 512 bits (128 hex chars) Secure High-security MACs
MD5 128 bits (32 hex chars) Broken Checksums only (legacy)

Use Cases

Specifications