Toolstia / SRI hash generator
SRI hash generator
Subresource Integrity lets a browser check that a file loaded from a CDN has not been changed. Paste the file or choose it, pick the hash types and copy the integrity value or the finished HTML tag.
Text you paste is hashed as UTF-8 with line breaks as \n. If your file uses Windows line endings, choose the file instead so every byte is hashed exactly as it is served.
How it works
- Paste the exact contents of the script or stylesheet, or choose the file.
- Pick sha256, sha384 or sha512. Sha384 is the usual choice.
- Enter the file URL if you want a full tag, then copy the integrity value or the tag.
What SRI does
When a tag carries an integrity value, the browser hashes the downloaded file and refuses to use it if the hash differs. A hacked CDN then cannot quietly change the code your visitors run.
Use the exact bytes
The hash covers every byte, including line endings and a final newline. Choosing the file is the safest way, because pasted text can lose a Windows line ending.
Crossorigin attribute
Files from another origin also need crossorigin set to anonymous, and the server must send CORS headers. The generated tag adds it for you.
Several hashes
You may list more than one hash separated by spaces. The browser then accepts the file if any of the strongest listed type matches.
Questions
Is my file uploaded?
Everything happens in your browser, and nothing you enter is sent anywhere.
Which algorithm should I pick?
Sha384 is the common choice and the one most guides show. Sha256 and sha512 are also allowed by browsers.
Why does the browser still block my file?
The most common reasons are a changed file, a missing CORS header on the CDN, or a hash made from text whose line endings differ from the served file.