Generate Subresource Integrity hashes for your JavaScript and CSS files. Paste the code, drop in files or fetch a CDN URL, choose sha256, sha384 or sha512, and copy a complete <script> or <link> tag with the integrity and crossorigin attributes. You can also verify an existing integrity value.
Last updated:
The file is downloaded by your browser directly from that server. Most CDNs (jsDelivr, unpkg, cdnjs) send the CORS header needed for both this tool and SRI.
Verify an integrity value
Advertisement
Advertisement
How to use the SRI Hash Generator
Choose the input: paste the file's code, upload files, or enter the CDN URL of the script or stylesheet.
Pick the hash algorithm. sha384 is the common default; you can add several.
Click Generate SRI Hash to compute the integrity value.
Copy the tag or just the integrity value and paste it into your HTML.
Verify later: paste an existing integrity value in the Verify box to confirm a file still matches.
How to add SRI to a script or stylesheet
Add two attributes to the tag: integrity with one or more hashes, and crossorigin so the browser fetches the file with CORS and is allowed to check it.
When the downloaded file's digest does not match, the browser blocks it and logs an error such as "Failed to find a valid digest in the 'integrity' attribute" in the console.
Integrity value format
Algorithm
Digest size
Base64 length
Example prefix
SHA-256
256 bits (32 bytes)
44 characters
sha256-
SHA-384
384 bits (48 bytes)
64 characters
sha384-
SHA-512
512 bits (64 bytes)
88 characters
sha512-
The digest is encoded in standard Base64 (with +, / and = padding), not hex. Several values are separated by spaces. The same tool from the command line: openssl dgst -sha384 -binary file.js | openssl base64 -A.
SRI tips
Use SRI only for immutable, versioned files. Pin the exact version in the URL (@3.10.1), never "latest".
Regenerate the hash every time you update the file. A build step can do it automatically.
Combine SRI with a Content Security Policy: CSP limits where scripts may come from, SRI guarantees what they contain.
Keep a fallback in mind: if a CDN changes a file, SRI blocks it, so test pages after any dependency upgrade.
Frequently asked questions
What is Subresource Integrity (SRI)?
Subresource Integrity is a W3C standard that lets a browser check that a script or stylesheet it downloads has not been changed. You add integrity="sha384-..." to the script or link tag; if the downloaded file's hash does not match, the browser refuses to run or apply it. It protects your site if a CDN or third-party host is compromised.
Which hash algorithm should I use?
Browsers support sha256, sha384 and sha512. sha384 is the most common choice and is what most CDNs publish. If you list several hashes, the browser uses the strongest algorithm present and the file must match one of the hashes for that algorithm.
Why do I need crossorigin="anonymous"?
For files loaded from another origin, the browser can only check integrity when the response is fetched with CORS. crossorigin="anonymous" requests the file without cookies, and the server must reply with an Access-Control-Allow-Origin header. Without it, a cross-origin resource with an integrity attribute is blocked.
Why does my hash not match the CDN's hash?
SRI hashes the exact bytes of the file. A single changed byte, a different line ending (CRLF vs LF), a missing final newline, or a minified versus unminified build gives a completely different hash. Pasted text uses LF line endings, so for an exact match upload the file or fetch it by URL.
Can I use SRI with files that change, like Google Fonts CSS or analytics scripts?
No. SRI only works for files whose content never changes, such as versioned library files ([email protected]). Resources that vary by browser or are updated in place, like Google Fonts CSS or tag manager scripts, will fail the check and be blocked.
How is the integrity value calculated?
The browser computes the SHA digest of the raw file bytes, encodes the binary digest in standard Base64 (not hex), and prefixes it with the algorithm name and a hyphen, for example the one-line script alert('Hello, world.'); has the integrity value sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.