SRI Hash Generator

Free SRI hash generator. Paste a CDN URL, upload a file or paste code to get sha256, sha384 or sha512 integrity attributes and a ready-to-copy script tag.

By

Advertisement

SRI Hash Generator for Script and Stylesheet Integrity

This SRI hash generator produces the integrity value you attach to a <script> or <link> tag so the browser will refuse to run a third-party file that has been altered. Give it a CDN URL, upload a file from disk, or paste the source directly, and it returns a base64-encoded SHA-256, SHA-384 or SHA-512 digest formatted exactly as Subresource Integrity expects — plus the complete HTML tag, with the crossorigin attribute already set, ready to paste into your template.

Hashing happens entirely in your browser through the Web Crypto API (crypto.subtle.digest). Pasted source and uploaded files never leave your machine, which means you can generate integrity hashes for unreleased internal bundles without shipping them to a third party first.

What Subresource Integrity Actually Does

When you load jQuery, a font loader or an analytics snippet from a public CDN, you are executing code you do not control on your own origin, with full access to your DOM, your cookies and your forms. If that CDN is compromised, or an intermediary tampers with the response, the injected code runs with your site's privileges. Subresource Integrity closes that gap. The browser fetches the resource, computes its cryptographic digest, and compares it against the value you declared. On a mismatch it discards the response and fires an error event — the script never executes and the stylesheet never applies.

The critical property is that verification is done by the browser, not by you or the CDN. An attacker who controls the CDN cannot supply a matching hash for modified content without breaking SHA-2, and an attacker who controls the network cannot rewrite your HTML if it is served over HTTPS.

Integrity Attribute Syntax

The value is a hash expression: the algorithm prefix, a hyphen, then the base64 encoding of the raw digest bytes. Note that it is base64 of the binary digest — not base64 of the hex string, which is the single most common mistake when people generate these by hand.

<script src="https://cdn.example.com/lib.min.js" integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC" crossorigin="anonymous"></script>

For a stylesheet the shape is the same: <link rel="stylesheet" href="https://cdn.example.com/app.css" integrity="sha384-..." crossorigin="anonymous">

Three details decide whether it works in practice:

  • crossorigin is mandatory for cross-origin resources. Without it the response is an opaque one that the browser will not read, so integrity checking cannot happen and the resource is blocked outright. Use anonymous for public CDN assets and use-credentials only when the request must carry cookies. The CDN must also return a permissive Access-Control-Allow-Origin header — this tool reports whether the URL you fetched does.
  • Multiple hashes are allowed, separated by whitespace (integrity="sha384-abc... sha512-def..."). The browser picks the strongest algorithm it recognises and requires only that one to match. Selecting several algorithms here produces exactly that, which is useful during a migration where two builds may be served.
  • The hash covers the exact bytes. A CDN that recompresses, re-minifies or appends a newline invalidates it. Always pin an immutable, versioned URL — never a @latest alias, whose whole purpose is to change underneath you.

Which Hash Algorithm to Choose

The SRI specification defines exactly three: sha256, sha384 and sha512. MD5 and SHA-1 are not permitted and browsers ignore them. All three produce a value your users' browsers compute at load time, so the cost difference is negligible in practice — the digest is calculated once per resource fetch, over a file that is typically tens of kilobytes.

  • sha384 — the practical default and what the tool preselects. 48 raw bytes become a 64-character base64 string. It is the algorithm the CDN copy-paste widgets emit, so it is also the one your team will recognise in review.
  • sha256 — 32 bytes, a 44-character base64 string, the shortest attribute. Cryptographically sufficient; choose it if attribute length genuinely matters to you.
  • sha512 — 64 bytes, an 88-character base64 string. The largest margin, and the sensible pick if a policy requires 256-bit security strength.

If you want raw digests for a purpose other than SRI — verifying a download, comparing file copies — the general hash generator gives you hex output across more algorithms.

How to Generate an SRI Hash

  1. Choose an input mode: URL to fetch a live CDN asset, File to upload a build artifact, or Text to paste source directly.
  2. Select the algorithms you want. Tick more than one to emit a multi-hash integrity attribute.
  3. Set crossorigin to anonymous unless the resource requires credentials, and tick async or defer if your script tag needs them.
  4. Read the results: the raw base64 digest, the finished integrity attribute, and the complete <script> or <link> tag. Copy the tag or download the output.
  5. Deploy, then confirm in DevTools that the resource loads with no integrity error in the console.

To check an existing tag rather than create one, fetch the same URL here and compare the generated hash against the integrity value already in your HTML. A mismatch means the file changed since the attribute was written — which is precisely the condition SRI exists to catch.

Enforcing SRI Site-Wide

Individual tags are opt-in, so a single forgotten script defeats the policy. Content Security Policy provides require-sri-for script style, which instructs the browser to reject any script or stylesheet loaded without an integrity attribute. Support has been uneven across browsers and the directive has drifted through the W3C process, so treat it as defence in depth rather than a guarantee, and keep a lint rule in CI that fails a build when a cross-origin <script src> lacks integrity. You can assemble the surrounding policy with the CSP generator and confirm what your site actually sends using the security headers analyzer.

Frequently Asked Questions

What is an SRI hash?+

An SRI hash is a cryptographic digest of a script or stylesheet, written as algorithm-base64digest in the integrity attribute of a tag. The browser recomputes the digest of what it downloaded and refuses to use the file unless the two match.

Is this SRI hash generator free?+

Yes — free, no account, no limit on how many hashes you generate.

Which algorithm should I use, sha256, sha384 or sha512?+

sha384 is the conventional default and what most CDNs publish. sha256 produces the shortest attribute and remains cryptographically sound; sha512 gives the widest margin. All three are valid SRI algorithms and all are widely supported.

Why does my script fail to load after adding integrity?+

Usually one of three causes: the crossorigin attribute is missing on a cross-origin resource, the CDN does not send an Access-Control-Allow-Origin header, or the file changed after you generated the hash. The browser console names which of these applies.

Do I always need crossorigin="anonymous"?+

For any resource on a different origin, yes. Without it the browser receives an opaque response it cannot inspect, so integrity cannot be verified and the load is blocked. Same-origin resources do not require it.

Can I put more than one hash in the integrity attribute?+

Yes. Separate hash expressions with whitespace. The browser selects the strongest algorithm it supports and only that one must match — helpful when two builds of a file may be served during a rollout.

Can I check an existing integrity attribute with this tool?+

Yes. Fetch the same URL in URL mode and compare the generated value with the one in your markup. If they differ, the file has been modified since the attribute was written.

Does SRI work with dynamically injected scripts?+

Yes, if you set the property when creating the element: assign el.integrity and el.crossOrigin before appending the node to the document. Setting them afterwards is too late.

Are my files uploaded to a server?+

No. Digests are computed locally with the Web Crypto API. Uploaded and pasted content stays in the browser. Only the URL mode makes a network request, and that request goes to the CDN you named.

Should I use SRI on my own same-origin files?+

It adds little security — an attacker who can alter those files can alter the HTML that declares the hash — and it adds a real maintenance cost, since every rebuild changes the digest. Reserve SRI for third-party origins you do not control.

This tool is provided for informational and educational purposes only. While we strive for accuracy, we make no warranties about the completeness or reliability of results.