This site is not affiliated with or endorsed by Cloudflare, Inc. It simply showcases experiments built using Cloudflare services.
Cloudflare Experiments

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 Reference

GET /hash

Returns a hex-encoded hash for the provided text.

Prop

Type

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 invalid text (INVALID_TEXT)
  • 400 - Unsupported algorithm (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

Limitations

  • Hashes plain text only; no file upload or streaming input
  • No HMAC, salting, or keyed hashing in this experiment
  • Input size is limited by Worker memory and request limits

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 dev

Test locally:

curl "http://localhost:8787/hash?text=hello"

Cloudflare Features Used

On this page