Crypto Hash
Compute SHA digests with the Web Crypto API at the edge
Compute SHA-256, SHA-384, or SHA-512 digests for any text input using the Web Crypto API in Workers.
API Endpoint
GET /hash
Returns a hex-encoded hash for the provided text.
text string (required)
Input string to hash (max 10,000 characters)
algorithm string (optional)
Hash algorithm: SHA-256 (default), SHA-384, or SHA-512
Example Request
curl "https://your-worker.workers.dev/hash?text=hello&algorithm=SHA-256"Success Response
algorithm string
The algorithm used for the digest
hash string
Lowercase hex-encoded digest
inputLength number
Length of the input text in characters
{
"algorithm": "SHA-256",
"hash": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824",
"inputLength": 5
}Error Response
{
"error": "Missing or invalid query parameter: text",
"code": "INVALID_TEXT"
}Error Codes
400- Missing or invalidtext(INVALID_TEXT)400- Unsupportedalgorithm(INVALID_ALGORITHM)
Use Cases
- Hash strings at the edge without shipping crypto libraries
- Verify content fingerprints in API workflows
- Learn Web Crypto (
crypto.subtle.digest) in Workers - Compare digest sizes across SHA-256, SHA-384, and SHA-512
Deployment
Deploy
No additional configuration required.
Test your deployment
curl "https://your-worker.workers.dev/hash?text=hello"Local Development
cd apps/experiments/crypto-hash
npm install
npm run devTest locally:
curl "http://localhost:8787/hash?text=hello"Cloudflare Features Used
- Workers - Edge compute runtime
- Web Crypto API -
crypto.subtle.digestfor SHA hashing