DevTools Logo

SRI Hash Generator

SRI Hash Generator

Turn pasted code or a local file into exact sha256/384/512 integrity attributes and ready-to-paste CDN tags — in your browser.

Runs in your browser
Try an example

Source code

0 B · 0 CRLF / 0 LF

Paste the exact file contents — never a <script> tag. A single CR, CRLF, BOM or trailing newline changes the hash.

0 B hashed · CRLF 0 · LF 0 · CR 0 · BOM no

Integrity output

Working…

Examples

Ready-to-paste CDN script

Input
console.log("hello from CDN"); with a final newline · CDN URL set to a jsdelivr path
Output
<script src="…" integrity="sha384-C5J83w9FFVqeu8ANq8/RxJUEqB2AxCnC8uKLf1L/fISfluFoS+VRxUuvHzz4Hti8" crossorigin="anonymous"></script>

The tag is composed with stable attribute order so it is easy to review in a diff.

Stylesheet link

Input
body { color: #222; } with a final newline · element switched to link (stylesheet)
Output
<link rel="stylesheet" href="https://cdn.example.com/style.css" integrity="sha512-…" crossorigin="anonymous">

The same digest works for a <script> or a <link>; only the surrounding tag changes.

Mismatch triage

Input
Paste source saved with CRLF, verify a hash generated from LF bytes
Output
NO MATCH — provided sha384-… / computed sha384-…, with CRLF 1 · LF 1 in the diagnostics

The readout makes the invisible byte difference visible before you re-download the file.

About this tool

SRI Hash Generator turns JavaScript or CSS source into the integrity attribute browsers actually check: sha256-<base64>, sha384-<base64> or sha512-<base64>. Paste the file contents, or pick a local file, and all three digests are computed locally with WebCrypto — no upload, no server round-trip.

The tool also composes a complete <script> or <link rel="stylesheet"> tag with crossorigin="anonymous", an optional referrerpolicy and a strongest-first combined attribute. Verify mode re-hashes the source and compares it with an existing integrity value, a quoted attribute or a whole copied tag, reporting a match, a mismatch with both values, or an explicit malformed/unsupported verdict.

Because SRI is byte-exact, the panel reports the hashed byte count, a UTF-8 BOM and CRLF/LF/CR counts. Those details explain most real-world failures: a CRLF copy, a missing final newline or a BOM produces a completely different digest even when the code looks identical.

What this tool does not do

  • No remote-URL fetching: the CDN file must be pasted or picked locally; fetching URLs would require a backend proxy decision.
  • Files are capped at 20 MB; WebCrypto's digest() is one-shot, so the chosen file is read into memory as one ArrayBuffer.
  • Pasted text is encoded as UTF-8; unpaired surrogates are replaced with U+FFFD. Use file mode for byte-exact binary hashing.
  • WebCrypto needs a secure context (HTTPS or localhost); the tool shows an explicit banner otherwise.
  • SRI does not protect the page itself, does not validate the CDN URL, and cannot make a hash pinned from malicious bytes trustworthy.
  • Nothing is uploaded or persisted beyond the session history shown on the page.

How to use this tool

  1. Paste or pick a file

    Use Paste for text you copied from a CDN, or File to hash the raw bytes of a local JS/CSS file up to 20 MB.

  2. Pick the preferred hash

    Choose sha256, sha384 or sha512 for tag composition, or turn on Combine all three for a multi-value attribute.

  3. Set the CDN URL

    Enter the exact URL the browser will request and choose script or link (stylesheet); optional module, defer, async and referrerpolicy flags are supported.

  4. Copy and pin

    Copy the complete tag into your HTML, or just the integrity attribute for hand-editing. Keep the hash alongside the CDN version — upgrading the library means regenerating it.

  5. Verify later

    Switch to Verify, paste the served bytes and the existing attribute or copied tag, and check the verdict before deploying a change.

Use cases

Harden static-site CDN includes

Pin jQuery, Bootstrap or analytics scripts so a compromised CDN cannot swap the bytes silently.

Review third-party tags

Re-hash the served file and compare with the integrity already present in a page under audit.

Teach integrity attributes

Show sha256/384/512 side by side and demonstrate how one CRLF changes everything.

Generate combined attributes

Emit sha512 + sha384 + sha256 for a deployment that needs algorithm fallbacks.

Output forms

FormMeaning
sha256-<base64>32-byte digest, 44 base64 characters; the smallest SRI option.
sha384-<base64>48-byte digest, 64 base64 characters; a common default for CDN tags.
sha512-<base64>64-byte digest, 88 base64 characters; strongest option, longer attribute.
Combined attributesha512-… sha384-… sha256-… in strongest-first order; browsers use the first algorithm they support that matches.
Raw hex / base64urlDebugging only — labelled “raw, not for SRI”; browsers reject these encodings in integrity.

SRI requires standard base64 with padding (the + and / characters are significant). Hex digests from checksum tools must be converted before use.

Common mistakes

Mistake:Hashing the <script src=…> tag instead of the file contents.

Fix:Paste the CDN file's body, not the HTML tag. The tool warns when markup is detected.

Mistake:Using a hex checksum in the integrity attribute.

Fix:Use the algo-<base64> row from the tool; hex must be converted and is shown only as a debug aid.

Mistake:Forgetting crossorigin on a cross-origin script.

Fix:Keep crossorigin="anonymous" (or an equivalent CORS mode) or the browser will ignore SRI.

Mistake:Reusing a hash after upgrading the CDN library.

Fix:Regenerate from the exact new file bytes; a version change almost always changes the digest.

Mistake:Assuming a mismatch means the CDN is compromised.

Fix:Check the byte count, BOM and line endings first — CRLF versus LF is the most common cause.

Frequently asked questions

What is the integrity attribute format?

It is an algorithm name, a hyphen, then a standard base64-encoded digest of the exact file bytes: for example integrity="sha384-C5J83w9FFVqeu8ANq8/RxJUEqB2AxCnC8uKLf1L/fISfluFoS+VRxUuvHzz4Hti8". Multiple options may be separated by whitespace, such as sha512-… sha384-…; the browser uses the first one it supports that matches.

Why base64 and not hex?

The Subresource Integrity specification defines the attribute as base64 so the digest is compact and directly decodable by the browser. Hex digests from checksum tools are longer and are rejected in an integrity attribute. This tool shows hex and base64url only as labelled debugging aids — never paste them into the tag.

Do I need crossorigin="anonymous"?

For a cross-origin CDN file, yes: SRI validation applies to CORS-enabled fetches, so a plain no-cors script load can cause the integrity check to be ignored. Keep crossorigin="anonymous" (or another CORS mode the host supports) on the tag, and ensure the CDN sends Access-Control-Allow-Origin.

Why won't my hash match?

Because SRI is byte-exact. CRLF versus LF, a UTF-8 BOM, a missing or extra final newline, or a different minified build all change the digest. Check the byte count and line-ending readout in the diagnostics panel, then re-paste the exact bytes the browser will receive. Verify mode shows both the provided and computed values to compare.

Can SRI protect against all CDN compromise?

No. SRI guarantees the file matches the hash you pinned. If the source was already malicious when you generated the hash, or the page itself is compromised, SRI will not help. It also does not check the URL or stop a future version from being served under the same URL — regenerate the hash whenever you upgrade the library.

Can I verify a whole tag I copied from a page?

Yes. Paste the tag into the Verify field; the integrity attribute is extracted automatically, including multi-value attributes. Unsupported legacy algorithms such as sha1 or md5 get an explicit unsupported verdict rather than a misleading mismatch.

Does the tool download the CDN file for me?

No. It is fully client-side and accepts pasted source or a local file up to 20 MB; nothing is uploaded. Adding remote-URL fetching would require a backend proxy decision, so paste or file mode is the supported path. WebCrypto requires HTTPS or localhost.

References & standards