SRI hash generator
Generate a Subresource Integrity hash for a script or stylesheet. Drop the file or paste its contents to get sha384, sha256 and sha512 and the ready-made tag.
The file is read in your browser. It is not uploaded.
The hash covers every byte. Pasting can change line endings or drop a final newline, and then the browser will block the file. Dropping the file itself is exact.
Optional, only written into the tag. This tool does not fetch it.
Integrity
Drop a file or paste its contents.crossorigin="anonymous" is required for a file from another origin, and that server must send an Access-Control-Allow-Origin header. Without both, the browser cannot check the hash and refuses the file.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the SRI hash generator
- Download the exact version of the script or stylesheet you intend to use.
- Drop the file, or paste its contents.
- Enter the URL the page will load it from, to complete the tag.
- Copy the tag into your page and load the page once to confirm the file is not blocked.
About this tool
Subresource Integrity (SRI) lets a page say exactly which file it expects from another server. You put a hash of the file in the integrity attribute of the script or link tag; the browser downloads the file, hashes it, and refuses to run it if the two differ. If a CDN is compromised or a file is swapped, your visitors get an error instead of someone else’s code.
The value is the hash algorithm, a dash and the Base64 digest of the file’s bytes. sha384 is the usual choice; sha256 and sha512 are also valid, and md5 and sha1 are not accepted. A file from another origin also needs crossorigin="anonymous" on the tag and CORS headers from the server, or the browser cannot check it and blocks it.
This tool hashes content you supply and never fetches a URL, so you decide what is trusted: hash the file you reviewed, not whatever the address returns today. SRI only works for files that never change, so pin an exact version in the URL. Dropping the file is more reliable than pasting, because a single changed line ending gives a different hash.
Sources
Questions
It is a cryptographic digest of a file, written as the algorithm name, a dash and the Base64 value, for example sha384 followed by the digest. The browser compares it with the file it downloads and blocks the file on a mismatch.
sha384 is the common recommendation and what most CDNs publish. sha256 and sha512 are equally accepted by browsers. You can list several values in one attribute; the browser uses the strongest one it supports.
Either the file’s bytes differ from what was hashed, or the cross-origin check failed. Check that the URL pins an exact version, that nothing minifies or rewrites the file on the way, and that the tag has crossorigin="anonymous" and the server sends Access-Control-Allow-Origin.
No. Any change to the file changes the hash, and the browser then blocks it. Use SRI with versioned, immutable URLs. For a script that updates in place, such as most analytics tags, SRI is not an option.