1. Home
  2. Developer tools
  3. SRI Hash Generator

SRI Hash Generator

Pin a third-party script or stylesheet to an exact hash so the browser refuses it if the CDN serves something different.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use SRI Hash Generator

  1. Open the file or paste its contents.
  2. Choose the algorithms.
  3. Copy the integrity value or the full tag.

Features

  • SHA-256, SHA-384 and SHA-512
  • Script and stylesheet tags with crossorigin
  • Several algorithms in one attribute
  • Files hashed locally
  • Checks an existing integrity value against content
  • Text or file input

Supported formats

Input

  • Any file (read in your browser)
  • Pasted code

You get

  • Integrity attribute
  • Script or link tag

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the SRI Hash Generator is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • The hash must match the exact bytes the server delivers.
  • The page does not fetch files from the web, so you must open or paste them.

Guide

Subresource Integrity: pinning scripts and styles to a hash

Many sites load scripts and styles from a content delivery network. That is convenient and fast, and it means your page runs whatever the CDN serves. If the CDN or the library’s publisher is compromised, every site that includes the file is compromised with it. Subresource Integrity, a W3C standard supported by all current browsers, lets your page say what the file must look like. The browser downloads it, hashes it and refuses to run it if the hash is different. This page produces the hash and the tag.

The attribute

The integrity attribute holds one or more tokens of the form sha384- plus a Base64 string. The Base64 is the digest of the file’s exact bytes. Browsers support SHA-256, SHA-384 and SHA-512. If you give several tokens, separated by spaces, the browser uses the strongest algorithm it knows and accepts the file if any token of that strength matches, which makes it possible to list two valid versions during a rollout. SHA-384 is the usual choice and the one most CDNs publish.

A worked example

Press Sample. The text is alert('Hello, world.');, 23 bytes with no trailing newline. The page gives three values: sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=, sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO and a longer sha512 value. It then writes a ready tag for the resource URL you enter, for instance <script src="https://cdn.example.com/app.min.js" integrity="sha384-H8BRh8j4…" crossorigin="anonymous"></script>. A single trailing newline would change every digest, which is why the page hashes exactly what you paste or open.

Why crossorigin matters

For a file from another origin, the browser checks integrity only if the request is made in CORS mode. That needs the crossorigin="anonymous" attribute on your tag and an Access-Control-Allow-Origin header from the server. Public CDNs send that header. If it is missing, the browser cannot read the bytes for checking and blocks the file. The tag builder adds the attribute for you.

Hash the delivered bytes

The hash has to match what the server delivers, not what is in your repository. A CDN may serve a minified or compressed variant, and some rewrite files. Compression like gzip does not matter, since the browser hashes the decoded bytes, but minification does. Open the file by its final URL, save it, and hash that file here. The “check an integrity value you were given” box recomputes a value from your content and tells you whether it matches.

Where SRI fits

SRI protects against changed third-party files. It does not protect against a malicious script that was always malicious, and it does not limit what an allowed script may do. Combine it with a Content-Security-Policy and with pinned library versions in the URL.

Limits

The page does not fetch files from the web, so open or paste the content yourself. It hashes locally. SRI works for script and link elements, not for dynamically created requests such as fetch or images.

Checked against the current version of the SRI Hash Generator on .

Frequently asked questions

Why does the browser block the file after I add integrity?

Either the bytes it received differ from the bytes you hashed, for example because the CDN minified or recompressed the file or because you hashed another version, or the file came from another origin without CORS headers, so the browser could not check it.

Can I use SRI for files that change often?

Not well. Every change breaks the hash, so SRI suits versioned, immutable files such as a library at a fixed version. For files you control, a content hash in the file name and a Content-Security-Policy work better.

Why does the browser block my script with an integrity error?

The delivered bytes differ from the ones you hashed, for example a minified or compressed variant or a changed version. Hash the exact file the server sends.

Do I need the crossorigin attribute?

For files from another origin, yes. The server must also send CORS headers, otherwise the browser cannot check the hash and blocks the file.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.