SRI Hash Generator

Generate Subresource Integrity hashes (SHA-256, SHA-384, SHA-512) for a JS or CSS file or pasted content and get a ready script or link tag.

Drop the JS/CSS file here or click to choose.js, .mjs, .css or any file

For files, drop the file directly for exact byte-level hashing.

About SRI Hash Generator

The SRI Generator calculates a Subresource Integrity hash for a JavaScript or CSS file and writes the ready-to-paste script or link tag, so browsers refuse a CDN file that has been changed.

Algorithms

SHA-256, SHA-384 (recommended) or SHA-512; pick more than one if you like.

Ready tags

Enter the file URL and you get a script tag for .js or a stylesheet link for .css, with the integrity value set.

Exact bytes matter

The hash covers every byte, including line breaks. Hash the exact file the CDN serves, or the page will block it.

Private

Files and pasted code are hashed in your browser.

The crossorigin attribute

Files from another domain need crossorigin="anonymous" in the tag, and the server must send CORS headers. Without them the browser cannot check the hash and blocks the file.

When the CDN file changes

Any change to the file, even an update served from the same URL, breaks the hash. Link to a fixed version number and make a new hash when you upgrade.

How to use it well

Drop the file on the page, or paste its content. Choose one or more algorithms: SHA-256, SHA-384 (recommended) or SHA-512. Choose the tag type or leave it on detection from the URL, and enter the public URL of the file. The tool shows the integrity value, for example sha384- followed by the Base64 hash, and a complete script or link tag with crossorigin set to anonymous.

Worked example

We pasted the one-line script console.log("hi"); with a final line break and used the URL https://cdn.example.com/app.js with SHA-384. The tool gave sha384-tdnWtBkj5+038HkeFOzlN0GdBuwDpXaWFs1Dhs560d67HmXunuEg4R3e+iEGk0Ho and a script tag with that integrity value and crossorigin="anonymous". We computed the SHA-384 of the same bytes separately with Python and got the identical value.

Tag detection

Changing the URL to https://cdn.example.com/site.css produced a link rel="stylesheet" tag with href and the same integrity attribute. The hash did not change, because it depends only on the content. If the URL has no clear extension, set the tag type yourself.

Line endings matter

A hash covers every byte, including line breaks. When we pasted the same text with Windows line endings (CRLF), the hash was still the same value in our test, so pasted content seems to be normalised. For exact byte-level results the page advises you to drop the file itself rather than paste, and that is the safer way when the file contains unusual characters or line endings.

Limits and cautions

The hash must be made from the exact file that the CDN will serve. If the CDN minifies the file or serves a different version, the check fails and the browser blocks the file. For a file on another origin, the host must also allow the cross-origin request with the right CORS headers, and the crossorigin attribute lets the browser make that request. Pin the file to a fixed version, because a hash for a floating latest file will break when it updates.

Is it private?

Files are hashed in your browser. In a test, pasting content and generating the tag made no upload requests, only the site's small analytics calls.

Who it is for

Web developers who load libraries from a CDN, security-minded site owners and teams that want protection against a compromised third-party host. SRI is one layer, so combine it with a content security policy and with versions you control.

How to use SRI Hash Generator

  1. Drop the JS or CSS file on the page, or paste its content.
  2. Choose the algorithm, with SHA-384 recommended.
  3. Enter the public URL of the file and choose the tag type, or leave it on detect.
  4. Copy the integrity value or the full tag into your HTML.

Help & FAQ

What is Subresource Integrity?

It is a browser feature that checks a downloaded script or stylesheet against a hash you give in an integrity attribute. If the file differs, the browser refuses to use it.

Which algorithm should we choose?

SHA-384 is recommended on the page. SHA-256 and SHA-512 are also accepted by browsers.

Why is crossorigin added to the tag?

For a file from another origin, the browser needs a CORS request to check the hash. The attribute crossorigin="anonymous" asks for that.

Will it work if the CDN changes the file?

No. If the served file differs by even one byte, the check fails and the file is blocked.

Should we paste or drop the file?

Drop the file for exact byte-level hashing. Pasted text can differ in line endings or encoding.

What does the tag type option do?

It chooses between a script tag and a link rel stylesheet tag. Detect from URL uses the file extension.

Can we use several algorithms at once?

Yes. With all three selected, the integrity attribute listed sha256-, sha384- and sha512- values separated by spaces.

Do we need to run it again after an update?

Yes. A new version of the file has a new hash, so generate the value again and update the tag.

Is our file uploaded?

No. It is hashed in your browser. In a test, only the site's small analytics calls were made.

Does SRI protect against everything?

No. It only checks that the file matches the hash. You still need to trust the version you hashed, and use other defences such as a content security policy.

Can we use SRI for images?

No. SRI applies to scripts and stylesheets in script and link tags.

More in Developer Tools

See all 39 in Developer Tools