Subresource Integrity (SRI) Hash Generator

Generate W3C Subresource Integrity (SHA-256, SHA-384, SHA-512) Base64 hashes and HTML script/link tags from code or local files in your browser.

HTML Element Type
CORS Attribute (crossorigin)
Tag Integrity Algorithm

Ready-to-Paste HTML Tag

<script src="https://cdn.example.com/app.min.js" integrity="sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO" crossorigin="anonymous"></script>
SHA-384W3C Recommended
sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO
SHA-256
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
SHA-512
sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw==

How W3C Subresource Integrity (SRI) Defends Against CDN Supply-Chain Attacks

Subresource Integrity (SRI) is a W3C web security specification that enables browsers to cryptographically verify that third-party JavaScript bundles (<script>) and CSS stylesheets (<link rel="stylesheet">) fetched from external Content Delivery Networks (CDNs) have not been modified or tampered with in transit.

If an attacker compromises a public CDN bucket, hijacks DNS, or injects skimmer code into a hosted library (a Magecart-style supply-chain attack), even a single altered byte changes the file's cryptographic digest. When the computed hash fails to match the Base64 digest declared in your HTML tag's integrity="sha384-..." attribute, the browser refuses to execute the script or apply the stylesheet.

CORS Requirements & Choosing Between SHA-256, SHA-384, and SHA-512

Because SRI validation inspects cross-origin asset bytes before execution, the HTML element must include a crossoriginattribute (typically crossorigin="anonymous") and the remote CDN must serve an Access-Control-Allow-Origin response header:

  • sha384 (W3C & Mozilla Observatory Recommended):Provides 384 bits of collision resistance with faster 64-bit word operations than SHA-256 and a more compact Base64 attribute string than SHA-512.
  • Binary-Safe Local Hashing: Drop any local.js, .mjs, or .css build artifact directly into the Local File mode above to compute exactUint8Array Web Crypto digests without newline conversion or server uploads.

Practical Real-World Use Cases

  • Hardening Third-Party CDN Scripts for PCI-DSS v4.0:Generate sha384- integrity attributes for analytics tags, payment widgets, and UI libraries loaded from jsDelivr, unpkg, or cdnjs to satisfy PCI-DSS v4.0 Requirement 6.4.3 script integrity controls.
  • Verifying Production Build Artifacts Before Release:Drop compiled Vite, Webpack, or Rollup .js and.css bundles into Local File mode to generate ready-to-paste<script> and <link> tags for static HTML templates.
  • Auditing Content Security Policy (CSP) Script Hashes:Compute exact Base64 SHA-256, SHA-384, and SHA-512 digests required byscript-src 'sha384-...' directives when locking down inline or external scripts alongside our Cryptographic Hash Generator.

Absolute Privacy

Whether you are hashing proprietary frontend bundles, pre-release JavaScript SDKs, or internal stylesheets, all SHA-256, SHA-384, and SHA-512 cryptographic digests are computed strictly inside your browser using the native hardware-accelerated crypto.subtle.digest Web Crypto API. No source code, build artifacts, or URLs ever leave your machine.

Frequently Asked Questions

Which Subresource Integrity (SRI) hash algorithm should I use: SHA-256, SHA-384, or SHA-512?

W3C and Mozilla Observatory recommend sha384 because it resists length-extension attacks, computes faster on 64-bit CPUs than SHA-256, and produces a shorter Base64 attribute than SHA-512.

Why is the crossorigin="anonymous" attribute required on script and link tags using SRI?

Browsers require CORS validation to inspect the raw bytes of a cross-origin CDN asset before execution. Without crossorigin="anonymous" (and an Access-Control-Allow-Origin header from the CDN), the browser will block the integrity check.