Free SRI Hash Generator for Scripts and Stylesheets
Hash a file or pasted code with SHA-256, SHA-384 or SHA-512, check an existing integrity attribute and copy script or link markup. It all runs in your browser.
Last updated 15 November 2026
This SRI hash generator makes the integrity value for a script or stylesheet and checks one you already use. Choose the file on this device or paste its contents, and the tool hashes those bytes in your browser with SHA-256, SHA-384 and SHA-512, then shows the value in the form the Subresource Integrity specification gives: the algorithm, a hyphen and a base64 digest. Paste an existing integrity attribute and it reports, expression by expression, whether each value matches this file, and whether the attribute as a whole passes when a browser checks only the strongest algorithm present. Type the file's address and it writes script or stylesheet link markup with the integrity and crossorigin attributes, ready to copy. Nothing is uploaded and the address is never requested. The guide below covers what SRI checks, why the hash has to come from a copy you trust, and what breaks when a file changes.
How to use this tool
- 1
Choose the file or paste its contents
Pick the copy of the script or stylesheet you trust, as a file on this device or as pasted text. A file is read in your browser and not uploaded. Files can be up to 10 MB and pasted text up to 2,000,000 characters.
- 2
Pick the algorithm and add any existing value
SHA-384 is selected first. To check an integrity attribute you already use, paste its value, or the whole attribute, into the optional box.
- 3
Generate the hash
Press Generate SRI hash. The tool hashes the bytes with SHA-256, SHA-384 and SHA-512, shows the value for the algorithm you picked and, if you pasted one, compares the existing value with this file.
- 4
Build and copy the markup
Choose script or stylesheet, choose anonymous or use-credentials for the crossorigin attribute, type the file's address, then copy the markup into your page.
What Subresource Integrity checks, and what it leaves alone
Subresource Integrity (SRI) lets a page state the exact contents it expects from a script or stylesheet. MDN describes it as a feature that enables browsers to verify that resources they fetch, for example from a CDN, are delivered without unexpected manipulation, by providing a cryptographic hash that a fetched resource must match. You add that hash to the element as an integrity attribute. MDN lists where it can be used: script elements, and link elements whose rel attribute value is stylesheet, preload or modulepreload. The W3C Subresource Integrity specification, a Working Draft, explains the gap it fills: TLS, HSTS and pinned public keys authenticate only the server, not the content, and an attacker or administrator with access to the server can manipulate content with impunity. Among its goals: compromise of a third-party service should not automatically mean compromise of every site that includes its scripts, and an author should be able to load a specific script, and not any script that happens to have a particular URL. What SRI leaves alone matters as much. A matching hash shows that the bytes are the bytes you hashed. It does not show that the code is safe, what it does once it runs, or what else it loads after it starts. The specification adds the integrity attribute to two elements, link and script, and notes that a future revision is likely to cover other subresources. Images and frames are outside this version of it. It also depends on the page that carries the hash: the specification says integrity metadata delivered by a context that is not a secure context, such as an HTTP page, only protects against a compromise of the server hosting the external resource, because a network attacker can alter or remove the digest in flight. It recommends delivering integrity metadata only to a secure context. Serve the page that carries the hash over HTTPS.
Hash a copy you trust, not whatever the CDN serves today
An integrity value is only as good as the copy it was made from. If you point a hash generator at the file a CDN is serving right now, the value records what that server sent at that moment. If the file had already been changed, the hash now approves the changed file, and browsers will load it. One of the specification's use cases runs the other way: an author who wants to include a third-party analytics script generates the integrity metadata to ensure that only the code that has been carefully reviewed is executed. Review first, then hash. MDN describes the risk. If an attacker gains control of a third-party host, they can inject arbitrary malicious content into its files or replace the files completely, which MDN says is referred to as a supply chain attack. A hash taken from that host after the fact protects against nothing that already happened there. A copy you trust comes from somewhere you can check apart from the server you are about to load it from: the package your package manager installed and your lockfile pins, a release you downloaded and compared with the publisher's published hash or signature, or a build your own pipeline produced. When a new version arrives, read what changed before you hash it, as you would for any other code change, and keep the hash in the same commit as the version bump, so the two change together. This is also why the tool starts with a file rather than pasted text. Pasted text is hashed as UTF-8 exactly as it sits in the box, so a copy that lost a trailing newline or changed its line endings on the way produces a different hash from the file the server sends. Hashing the file itself avoids that.
What a browser does when the hash does not match
MDN says the browser first selects the hashes made with the strongest hash function present and ignores the rest; if the file's hash matches any of those, the browser loads the resource, and otherwise it refuses to load the resource and returns a network error. The specification puts it as refusing to render or execute a response that fails the check, and notes that an error event is fired, which a developer can catch to load a fallback copy from a secondary, trusted source. Which values count depends on the algorithms. The specification ranks SHA-256, SHA-384 and SHA-512 from weakest to strongest, and when an attribute carries several hash expressions it says the user agent chooses the strongest hash function in the list and uses that to validate the response. A SHA-256 value that matches does not help if a SHA-512 value sits beside it and does not. Several values of the strongest algorithm are allowed, and one match among them is enough, which lets a page accept two different versions of a file. An expression whose algorithm is not one of the three is skipped, and if none is left, the specification says validation acts as if no integrity value was provided. The comparison in this tool follows those rules. The rule has a consequence for files that change at one address. An address a vendor reuses for every release, or a file a vendor updates in place, serves new bytes when the vendor ships a change. Your integrity value still describes the old bytes, so the browser refuses the new file, and whatever depends on it stops working until you update the hash. Point the markup at a versioned address that does not change, and move the version and the hash together after reviewing the new release. The specification also says that proxies and other intermediate servers which modify responses must keep the digest in sync with the new content, and that those serving the resources should send Cache-Control: no-transform.
Why the markup carries a crossorigin attribute
A script or stylesheet from a CDN, a payment provider or a widget vendor comes from another origin. MDN says cross-origin requests that use Subresource Integrity must use the CORS protocol, so the crossorigin attribute must be included in the markup. The specification gives the reason. It requires integrity-protected cross-origin requests to use CORS to ensure that the resource's content is explicitly shared with the page that asked for it. Without that rule, an attacker could load a resource from another origin with a known digest and watch for load failures to learn whether it has certain content, which the specification says might reveal, for example, whether or not a user is logged into a particular service. It calls an attempt to use SRI without CORS a logical error. The crossorigin attribute decides how that CORS request is made, and MDN describes both values. With anonymous, the request uses CORS and its credentials mode is same-origin, so credentials such as cookies, client-side TLS certificates and HTTP authentication headers are included only if the destination has the same origin. With use-credentials, the credentials mode is include, so credentials are always included, even for cross-origin requests. An empty value, as in the bare word crossorigin, is the same as anonymous. For a public library on a CDN, anonymous fits: the file is the same for everyone, and nothing personal needs to travel with the request. Choose use-credentials only when the file's server needs to recognise the visitor and has been set up for credentialed requests from your origin. MDN's CORS guide says that when responding to a credentialed request, the server must specify an explicit origin rather than the wildcard. This tool cannot see the server's response headers, so check the request in your browser's developer tools after you deploy.
What this tool does with your file, and what it cannot tell you
The generator runs in this page. A file you choose is read in your browser and hashed with the browser's Web Crypto digest function; pasted text is encoded as UTF-8 first. Nothing you choose, paste or type is uploaded, and the address you type is written into the markup as an escaped attribute value without being requested. Each run hashes the bytes with SHA-256, SHA-384 and SHA-512, and an existing value you paste is checked for each of those three algorithms it names. SHA-384 is selected first because the specification's security considerations say that, at the time of writing, SHA-384 is a good baseline. The comparison follows the specification's parse-metadata steps with three differences. It splits the value on any whitespace, as MDN describes the attribute, where the specification's steps split on spaces only. It ranks an algorithm written in capitals, such as SHA384, as its lower-case form, which the specification's ranking step does not cover. And it reads the value as pasted, without decoding HTML character references such as + that a browser decodes when it parses the page. It reads each hash expression as an algorithm, a hyphen and a base64 value, sets aside any options after a question mark, and compares each value exactly, letter case and padding included. Each expression is reported as a match, a mismatch, a missing value or an algorithm the tool does not handle, and the tool says whether the whole attribute passes for this file under the strongest-algorithm rule. Files can be up to 10 MB and pasted text up to 2,000,000 characters, and anything larger is refused, so a value on screen always covers the whole input. An existing value can be up to 8,000 characters, and the result lists its first 20 expressions while the overall check covers all of them. The tool cannot tell you whether the copy you hashed is the one you should trust, whether the file's server sends the CORS headers a browser needs, whether the code is safe to run, or whether the file at that address will change after you publish.
Sources
- MDN Web Docs: Subresource Integrity
- W3C: Subresource Integrity (Working Draft)
- MDN Web Docs: crossorigin HTML attribute
- MDN Web Docs: Cross-Origin Resource Sharing (CORS)
Worked example
An invented example, not taken from any site: a developer checks a one-line script against an integrity attribute copied from an older page.
- Pasted text
- alert('Hello, world.');
- Bytes hashed
- 23
- Existing value
- one correct SHA-256 value and one out-of-date SHA-512 value
- Algorithm picked
- SHA-384
The SHA-256 value matches, but a browser checks only the SHA-512 value, which does not, so the integrity check fails for this script.
After confirming this is the script the page should run, the developer replaces both values with the SHA-384 value the tool produced. That leaves one algorithm for the browser to check, and its value matches.
Who uses this tool
Developers adding a CDN library
Hash the release you installed and reviewed, then copy script markup that ties the CDN copy to those exact bytes.
Sites with vendor scripts on checkout pages
Before a release, check that the integrity values already in the page still match the vendor files you reviewed and kept.
Developers chasing a blocked script
Paste the attribute from the page and choose the file you expected, to see which expression fails, whether a value differs only in its padding, and whether a stronger algorithm in the attribute means the browser ignores a value that matches.
Reviewers checking a pull request
Confirm that a new integrity value in a change matches the file the change adds, before it is merged.
Frequently asked questions
Does this SRI hash generator upload my file?
No. The file is read in your browser and hashed with the browser's Web Crypto digest function. Pasted text and the address you type stay in the page too, and the tool never requests the address. When a hash is generated, the page sends one analytics event that names the tool and the page, and nothing from your input.
Which algorithm should I use for the integrity attribute?
The specification requires browsers to support SHA-256, SHA-384 and SHA-512, and ranks them in that order from weakest to strongest. Its security considerations say that, at the time of writing, SHA-384 is a good baseline, which is why the tool selects it first. If you list more than one algorithm, a browser checks only the strongest one present, so at least one value of that algorithm has to match the file.
Why does my page block a script after I added the integrity attribute?
Check two things. The file may differ from the copy you hashed, or the CORS part may be missing: the markup has no crossorigin attribute, or the file's server does not send an Access-Control-Allow-Origin header that allows your page. MDN says that when the hash does not match, the browser refuses to load the resource and returns a network error, and that cross-origin requests using Subresource Integrity must use CORS, so the markup needs a crossorigin attribute. Paste your attribute here with a downloaded copy of the served file to see which expression fails.
Can I hash the file straight from the CDN address?
The tool does not fetch addresses, by design. A hash of whatever a server sends today only records what it sent, so if the file had already been changed, the hash would approve the changed copy. Hash the copy you installed, reviewed or built yourself, then use the address only in the markup.
What happens when the file at an unversioned URL changes?
The browser hashes the new file, the result no longer matches your integrity value, and the browser refuses to load it, so whatever depends on that file stops working until you update the hash. Use a versioned address that does not change, and update the version and the hash together after reviewing the new release.
Should I choose anonymous or use-credentials for crossorigin?
MDN says anonymous sends credentials such as cookies, client-side TLS certificates and HTTP authentication only when the destination has the same origin, while use-credentials always sends them, even for cross-origin requests. A public library needs no credentials, so anonymous suits it. Choose use-credentials only when the file's server must recognise the visitor and is set up to accept credentialed requests from your site.