# Hash generator

> Compute SHA-256, SHA-384, SHA-512, or SHA-1 hashes of text or local files in the tab.

Live HTML: https://plaintools.io/dev/hash-generator

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

You have text or a local file and need its cryptographic hex or base64 checksum without uploading it.

## When not to

Do not use SHA-1 for security or digital signatures (it is cryptographically broken; legacy verification only). Multi-gigabyte files may exceed browser memory.

## Inputs

- **algorithm:** SHA-256 (default) | SHA-384 | SHA-512 | SHA-1 (legacy).
- **data:** Plain text string (UTF-8) or binary buffer.

## Outputs

- **hex:** Lowercase hexadecimal string representation of the digest.
- **base64:** Standard base64 encoded digest.
- **digestBytes:** Digest length (SHA-256=32B, SHA-384=48B, SHA-512=64B, SHA-1=20B).

## Steps

1. Select algorithm: SHA-256, SHA-384, SHA-512, or SHA-1. Warn that SHA-1 is legacy and insecure.
2. If input is text: encode to UTF-8 bytes using TextEncoder(). If input is a File: read into an ArrayBuffer via file.arrayBuffer().
3. Call Web Crypto API: `await crypto.subtle.digest(algorithm, bytes)`.
4. Convert the resulting ArrayBuffer to hex: map each byte to 2-character zero-padded lowercase hex.
5. Convert the ArrayBuffer to base64: byte-to-binary string, then btoa.
6. Never upload bytes or transmit them over the network.

## FAQs

### Does this hash generator send my files or text to a server?

No. Calculations run locally using the browser’s Web Crypto API (crypto.subtle.digest). Files are read into a local memory buffer and are never uploaded or transmitted over the network.

### Which hash algorithms are supported?

SHA-256, SHA-384, SHA-512, and SHA-1. SHA-256 is the standard default for data integrity. SHA-1 is labeled legacy because it is cryptographically broken and should only be used to verify existing legacy checksums.

### Why are both hex and base64 outputs provided?

Hexadecimal is standard for file checksums (such as sha256sum) and git commits. Base64 is commonly used for HTTP headers, Subresource Integrity (SRI) attributes, and API authentication tokens. Both can be copied with one click.

### Can I hash large files?

The tool reads files directly into an in-memory buffer in your browser tab. Typical files up to hundreds of megabytes hash quickly, limited only by your computer’s available memory.

### Is MD5 supported?

No. MD5 is not part of the standard Web Crypto API (SubtleCrypto) in modern web browsers due to collision vulnerabilities. Use SHA-256 or SHA-512 for secure checksums.

### How do I calculate hashes without this page?

Select algorithm: SHA-256, SHA-384, SHA-512, or SHA-1. Convert text to UTF-8 bytes with TextEncoder, or read a file as an ArrayBuffer. Call crypto.subtle.digest(algorithm, buffer). Convert resulting bytes to lowercase hex (pad with leading zero to 2 hex digits per byte) or base64 with btoa.

## Related tools

- [JWT decoder](https://plaintools.io/dev/jwt-decoder.md) — HTML: https://plaintools.io/dev/jwt-decoder
- [Text diff checker](https://plaintools.io/dev/text-diff-checker.md) — HTML: https://plaintools.io/dev/text-diff-checker
- [Timestamp converter](https://plaintools.io/dev/timestamp-converter.md) — HTML: https://plaintools.io/dev/timestamp-converter
- [Subnet calculator](https://plaintools.io/dev/subnet-calculator.md) — HTML: https://plaintools.io/dev/subnet-calculator
