SRI Hash Generator
Get the integrity value and tag for a script or stylesheet, and check the one you have.
Try before you buy.
- Free preview: the first lines of the tags, the first integrity values and the first checks of a value you paste (a single file shows its verdict, its value hidden).
- Locked until you unlock it: download and copy.
- Unlock: Pro pass, ₹179 for 30 days or ₹79 for 1 week, a one-time payment that never renews. Unlock: Pro pass, $5.99 for 30 days or $2.99 for 1 week, a one-time payment that never renews.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
What to hash
End it with / to add each file name. Leave empty to use the file names as they are.
Hashed as UTF-8. One different byte (a final newline, CRLF line ends) gives another hash, so drop the file itself when you can.
Files from another domain are checked only with CORS.
Integrity
Choose a file or paste code to hash it.
| File | Size | Hash | Integrity value |
|---|
Check an integrity value
Checked against every file above, the way a browser checks it.
| File | Result | Why |
|---|
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
About the SRI Hash Generator
Subresource Integrity (SRI) lets a page say exactly which file it expects from a CDN or another server: the integrity attribute carries a hash of the file, and the browser refuses to run a script or apply a stylesheet whose bytes do not match. If the CDN is hacked or the file changes, the browser blocks the changed file instead of running it.
Drop your scripts and stylesheets here (or paste the code) and the page computes their SHA-256, SHA-384 or SHA-512 digests in your browser and writes the <script> and <link> tags with integrity and crossorigin, for one file or many at once. To check a tag you already have, paste its integrity value: the page applies the specification’s rules — only the strongest algorithm counts, the base64 text must match exactly, unsupported algorithms check nothing — says whether the file would load, and points out a value that browsers read differently.
Without a pass the result is a free preview: the first lines of the tags, the first integrity values and the first checks (a single file shows its verdict with its value hidden). Every value and tag, and copying or downloading them, unlock with a Pro pass.
How to use it
- Choose Files and drop the exact files you serve (best: download them from the CDN URL you use), or choose Paste code.
- Pick the hash: SHA-384 is the usual choice. Add a second algorithm only for a planned change of file.
- Enter the address the page loads the file from (for files, the folder they are in), and keep
crossorigin="anonymous"for files on another domain. - With a pass, or once this result is unlocked, copy the tags into your HTML; the free preview shows their first lines. The file list and sizes always show.
- To check an existing tag, paste it or its integrity value under Check an integrity value: each file shows whether a browser would load it, and why not.
Examples
alert('Hello, world.'); (pasted, SHA-384)sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO
The same value the W3C specification gives for this script.
bootstrap.min.css · folder https://cdn.example.com/bootstrap/5.3.3/css/
<link rel="stylesheet" href="https://cdn.example.com/bootstrap/5.3.3/css/bootstrap.min.css" integrity="sha384-…" crossorigin="anonymous">
integrity="sha256-… sha512-…" where only the sha256 value is up to date
Does not match: browsers check only the strongest algorithm (sha512); the sha256 entry matches, but browsers do not fall back to it.
Common uses
- Pinning jQuery, Bootstrap, fonts’ CSS or analytics scripts loaded from a public CDN, so a compromised CDN cannot run code on your site.
- Adding integrity to the script tags your build or CMS writes, for files you host on a separate static domain.
- Finding out why a browser blocks a script with an “integrity” error in the console.
- Checking that a vendor’s published SRI value belongs to the file you actually downloaded.
How browsers check integrity
- Algorithms. Browsers must support
sha256,sha384andsha512. MD5 and SHA-1 are not accepted; a value with only those checks nothing. - Strongest wins. With several values, the browser uses only those of the strongest algorithm listed, and the file passes if any of them matches. A matching weaker value does not help.
- Exact bytes. The digest is of the file as the browser receives it (after any compression is undone), so a re-minified file, another version on the same URL, CRLF instead of LF line ends or a byte-order mark all break it. Hash the file you serve, not a copy you edited.
- Exact text. The specification compares the base64 value as written: standard base64 with its
=padding, and the algorithm in lower case. Browsers are not all that strict: Chromium-based ones also read URL-safe characters (-,_) but ignore an algorithm name in capitals (and then check nothing), so a value written another way can load in one browser and fail in another. - CORS. A file from another origin is checked only if it is fetched with CORS: add
crossorigin="anonymous"and make sure the server sendsAccess-Control-Allow-Origin. Without CORS the file is blocked. - Failure. A file that fails is not executed or applied, the request ends as a network error and the element fires an
errorevent, which you can use to load a fallback copy.
Source: W3C Subresource Integrity.
Integrity and your Content Security Policy
SRI and CSP work together: a policy decides which hosts may serve scripts, integrity decides which exact files. A strict CSP can also allow a script by its hash (script-src 'sha384-…') — the same kind of digest this page computes. Build a policy with the CSP Generator, and check the headers of your page with the Security Headers Checker.
Limitations
- Nothing is downloaded from a URL: open or download the file from your CDN and drop it here. Pasted code is hashed as UTF-8 with the line ends you choose, which must be the bytes the server sends.
- The SRI specification covers scripts and stylesheets (and their preloads); images, fonts and frames have no integrity attribute.
- A file that changes on every request (an analytics script without a version in its URL) cannot be pinned: its next version will be blocked.
Privacy
On this device: nothing is sent
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, SRI Hash Generator shows the first lines of the tags, the first integrity values and the first checks of a value you paste (a single file shows its verdict, its value hidden). Until you unlock it, the result can’t be downloaded or copied. A Pro, Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Which hash should I use?
SHA-384 is the usual choice and the one the specification’s examples use; SHA-256 and SHA-512 work too. Listing several algorithms does not make the check stronger — browsers use only the strongest one listed.
Why does my browser say the integrity check failed?
The file served is not byte-for-byte the file the hash was made from: a new version on the same URL, a CDN that re-minifies or rewrites the file, changed line ends, or a hash made for another file. Paste the tag under Check an integrity value and drop the file you actually receive (download it from the same URL) to see which.
Do I need crossorigin="anonymous"?
For a file on another origin, yes: integrity is checked only on a CORS request, and the server must answer with Access-Control-Allow-Origin (check its response headers). For a file on your own origin the attribute is harmless.
How do I make the hash on the command line?
openssl dgst -sha384 -binary file.js | openssl base64 -A, then put sha384- in front of the result. For a file on a CDN: curl -s https://cdn.example.com/file.js | openssl dgst -sha384 -binary | openssl base64 -A.
Is anything uploaded?
No. Files are read and hashed by your browser with its built-in Web Crypto; nothing leaves your device.