Use this free SRI hash generator to add subresource integrity to scripts and stylesheets loaded from a CDN or another origin. Choose a local file, or a URL that allows cross-origin requests, and the tool calculates the integrity value and gives you a tag ready to paste. Hashing runs in your browser.
Subresource integrity protects against a changed or compromised third-party file. It does not protect against a compromised site you wrote yourself, so host your own code on your own origin where you can.
How to use the SRI hash generator
- Local file: choose the exact file your page loads. This is the most reliable option.
- URL: paste the file address. It works only if the server sends a CORS header allowing this site.
- Algorithm: sha384 is the common choice. sha256 and sha512 are also supported.
- Tag: copy the generated script or link tag into your page.
Integrity value format
| Part | Example | Meaning |
|---|---|---|
| Algorithm | sha384- | The hash function used. |
| Digest | Base64 text | The hash of the file's exact bytes, in Base64. |
Worked example
The SHA-384 integrity of the text "hello" with no trailing newline is sha384-WeF0h3dEjGnea4ANejO7+5/xtGPkQ1TDVTvNucZm+pASWjx5+QOXvfX2oT3oKGhP. A tag using it looks like this: a script element with the src, integrity, and crossorigin="anonymous" attributes.
Common SRI mistakes
- Hashing a different copy. Minified and unminified versions have different hashes. Use the exact file the tag loads.
- Forgetting crossorigin. Cross-origin resources need crossorigin="anonymous" for the integrity check to run.
- Updating the library without updating the hash. A new version breaks the page until the integrity value is changed.
- Assuming it protects everything. It only covers the resources you list with an integrity attribute.
Frequently asked questions
Is this SRI hash generator free?
Yes. There is no sign-up and no limit on how many hashes you create.
Is my file uploaded?
A local file is read in your browser and is not uploaded. In URL mode, the browser downloads the file directly from its address, and nothing is sent to our server.
Why does my URL fail to load here?
The browser reads a cross-origin file only if the server sends an Access-Control-Allow-Origin header that allows this site. If it does not, download the file and use the local file option.
Do I need crossorigin on the tag?
Yes, for cross-origin files. Without crossorigin="anonymous", the browser cannot check the integrity value of a cross-origin resource.
Which algorithm should I use?
sha384 is a common choice and matches what many CDNs publish. Use the one the CDN lists if it gives one.