01What is SRI Hash Generator?
When you load jQuery or Bootstrap from a CDN, you trust that server to send the same bytes every time. Subresource Integrity, a W3C specification, lets you pin those bytes. You add an integrity attribute to the script or link tag, and the browser refuses to run the file if its hash doesn't match. This tool works out that attribute for you. There are two input modes. Content mode is the default. You paste the file's text, the page encodes it as UTF-8 and hashes it exactly as pasted, with no trimming. URL mode fetches the file straight from your browser and hashes the raw bytes that arrive. Our server never sees the request. That only works when the CDN sends CORS headers, which jsDelivr, cdnjs, unpkg and code.jquery.com do. If the fetch fails, you get an error suggesting you paste the content instead. You tick any mix of SHA-256, SHA-384 and SHA-512, and all three are ticked when the page loads. Each hash comes from the browser's Web Crypto API. The raw digest is Base64 encoded and prefixed with the algorithm name, which is the format the SRI spec asks for. That means you'll get the same value as running openssl dgst -sha384 -binary on the file and Base64 encoding the result. For example, pasting console.log('hi'); with SHA-384 gives sha384-N/kNTWnJNWFiX3986bEX2C8zQwRUBkBb+1iXYcjLeDamK9eB8enZHTdXBY4fboJh. Add one newline at the end and the value becomes sha384-S/E9Ac... with nothing in common. In URL mode, each result also comes with a Full HTML Tag. You pick Script or Stylesheet, and it builds the matching tag with the integrity value and crossorigin="anonymous". In Content mode you get the bare integrity value instead. That newline example points to the main limit. A text box can change your bytes without you noticing. Browsers usually normalise line endings in a textarea, and copying a file can drop its final newline. Either change gives a different hash, and the browser will then block a file that's actually fine. For a file you don't control, URL mode is the safer choice. Also keep in mind that a hash checks bytes, not intent. If the file was already tampered with when you hashed it, SRI will faithfully pin the bad version.
Frontend developers who load scripts or stylesheets from a public CDN and want the browser to block any copy that has changed. The tool runs entirely in your browser, so your data never leaves your device.
02How to use SRI Hash Generator
- Under Input, choose Content to paste the file's text or URL to fetch it from a CDN
- In URL mode, pick Script or Stylesheet under Tag so the right HTML tag is built
- Tick the algorithms you want: SHA-256, SHA-384 and SHA-512 are all ticked by default
- Enter the Resource URL or paste the File Content, then click Generate SRI Hash
- Copy the Integrity Attribute, or in URL mode the Full HTML Tag, into your page
03Worked examples
- Input:
Content mode, SHA-384: console.log('hi'); - Result:
sha384-N/kNTWnJNWFiX3986bEX2C8zQwRUBkBb+1iXYcjLeDamK9eB8enZHTdXBY4fboJh - Input:
Content mode, SHA-384: console.log('hi'); followed by a newline - Result:
sha384-S/E9AczxJ45AfnRY5VLtw/IwaqqEyuZpg/47V2uDmGHkP2qdE/iuDb2BNHoj+IFy - One trailing newline changes the whole hash, so the file must match byte for byte.
- Input:
Content mode, SHA-256: console.log('hi'); - Result:
sha256-V7Q9/DwmqvdPGQ4dy6ncNMsD52hvmuqtLSJ0fK6Mdr8= - Input:
Content mode, SHA-384: body{margin:0} - Result:
sha384-624hJ8nEe/uDdupZe/6Ug/U4fU/QRVsiTGq3cDxFtyteEAMgXERWXujDDQlJgeyk - Input:
Content mode, SHA-256: alert("é"); - Result:
sha256-t5clFJ682jvyxw1gU0GqKym3t18fJr/fRYtIKxUvH5o= - Non-ASCII text is hashed as UTF-8, so é counts as two bytes.
04Common use cases
- Adding an integrity attribute to a jQuery, Vue or React script tag loaded from a public CDN
- Pinning a Bootstrap or other CSS framework stylesheet so a changed file is blocked rather than applied
- Generating a fresh hash after bumping a CDN library version in your HTML
- Checking an existing integrity value against the file the CDN serves today, when a page suddenly starts blocking a script
- Hashing a small self-hosted script you serve from a separate static domain
- Getting SHA-256, SHA-384 and SHA-512 values at once when a policy asks you to list more than one
05Tips
- Keep crossorigin="anonymous" on the tag. Cross-origin files are fetched without CORS otherwise, and the browser can't check the hash, so the file fails to load.
- When a tag lists several hashes, the browser uses the strongest algorithm it supports. Listing sha384 alone is a common and simple choice.
- Pin an exact version in the CDN URL, such as [email protected], not a floating tag. A file that changes under a moving URL will break your SRI check.
- If a hash from Content mode doesn't match in the browser, try URL mode on the same file. Line endings and a missing final newline are the usual cause.
06Related concepts
Subresource Integrity, CDN security, Supply chain attack, Crossorigin attribute.
Frequently Asked Questions
What is SRI Hash Generator?
SRI Hash Generator is a free, browser-based developer tool on AIDToolStack. Generate Subresource Integrity hashes for scripts and stylesheets. It requires no installation or sign-up and works entirely in your browser.
Is SRI Hash Generator free to use?
Yes. No sign-up, no fees and no usage cap.
Does SRI Hash Generator store my data?
No. It runs in your browser; nothing is uploaded.