SRI Generator - Generate SRI Hash Online

Generate Subresource Integrity hashes for scripts and stylesheets

What is SRI?

Subresource Integrity (SRI) allows browsers to verify that resources from the CDN have not been changed.

If the file is modified (by an attacker), the browser will refuse to load, protecting users from malicious code.

SRI Hash Generator - Free Online Subresource Integrity Hash Generator

Tool to generate SRI (Subresource Integrity) hashes for JavaScript and CSS files from a free online CDN. Supports SHA-256, SHA-384, SHA-512 algorithms. Automatically generate script tag and link tag with integrity attribute. Protect your website from CDN compromise and supply chain attacks. Fetch resource and calculate hash directly in the browser. Copy tags with one click. Useful for web developers and security engineers.

Outstanding features

Supports 3 algorithms: SHA-256, SHA-384 (recommended), SHA-512
Automatically fetch resources from URL and calculate hash
Generate script tags complete with integrity and crossorigin attributes
Generate link tag cho CSS files
Copy hash or full tag with one click
Displays private integrity hashes for use in build tools
Handle on browser - doesn't send URL to server
Supports all CDNs: cdnjs, unpkg, jsdelivr, Google, Microsoft...
Error handling cho CORS issues
Explain what SRI is and why it is needed

What is SRI and why do we need Subresource Integrity?

Subresource Integrity (SRI) is security feature allows browsers to verify that resources (JS, CSS) from CDN don't changed. When you loads script from third-party CDN, there is risk: CDN is hacked and file is injected with malicious code, Man-in-the-middle attack changes file, CDN serves wrong version. SRI solves by: Browser calculates hash belonging to downloaded file, compares with hash in integrity attribute, if Are does not match, browser rejects execute. This is defense-in-depth important for supply chain security. Many security standards (CSP, PCI-DSS) recommend requiring SRI for third-party resources.

Benefits when used

  • Protection against CDN compromise - if the CDN is hacked, malicious code cannot be executed
  • Detect tampering - know immediately if files have been changed
  • Supply chain security - reduces risk from third-party dependencies
  • Compliance - meets security standards such as PCI-DSS
  • User protection - protects users from malicious scripts
  • Audit trail - integrity hash is proof of the exact version used

How to use SRI Hash Generator

  1. 1Copy URL of JavaScript or CSS file from CDN (eg https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js)
  2. 2Paste the URL into the input box
  3. 3Choose algorithm: SHA-384 is recommended (balance between security and performance)
  4. 4Click 'Generate' button to fetch file and calculate hash
  5. 5Wait for the tool to fetch resources (may take a few seconds depending on file size)
  6. 6Copy Integrity Hash if used in build tools (webpack, vite...)
  7. 7Or copy the complete Script Tag / Link Tag to paste into HTML
  8. 8Paste into your HTML, replacing the old script/link tag
  9. 9Test website to ensure resources load correctly

Frequently Asked Questions (FAQ)

What is SRI?

SRI (Subresource Integrity) is a W3C specification that allows browsers to verify the integrity of resources fetched from CDN. The browser calculates the cryptographic hash of the downloaded file and compares it with the hash in the integrity attribute. If there is no match, the browser blocks the resource. This protects against CDN compromise, MITM attacks, and accidental file corruption.

Should I use SHA-256, SHA-384 or SHA-512?

SHA-384 is recommended by W3C and is the default of many tools. SHA-256 is also secure and has a shorter hash. SHA-512 is the most secure but has a longer hash. In practice, all three are secure enough for SRI. SHA-384 is good balance. Browsers support all 3 algorithms.

What is crossorigin='anonymous'?

When using SRI, the browser needs to access the response body to calculate the hash. With cross-origin requests (CDN), CORS is needed. crossorigin='anonymous' tells browser to make CORS request without credentials. If this attribute is missing, SRI will fail for cross-origin resources. Most CDNs have CORS enabled.

CORS error when generating hash?

The tool needs to fetch files to calculate hash. If the CDN does not enable CORS, the browser blocks the request. Most major CDNs (cdnjs, unpkg, jsdelivr) have CORS enabled. If you get an error: Check if the URL is correct, try another CDN, or use a command line tool like shasum.

Does SRI affect performance?

Minimal. The browser needs to calculate the hash of the downloaded file, but modern browsers are very fast. Hash calculation is O(n) with file size. With typical JS/CSS files (a few hundred KB), the overhead is negligible. Security benefit outweighs tiny performance cost.

When is SRI failandresource blocked?

SRI fails when: File content changes (CDN updates version, file is tampered). Hash algorithm does not match. integrity attribute syntax is wrong. CORS is not enabled. When it fails, the browser logs errors in the console and does not execute script / apply styles. The website can break so it needs to be tested carefully.

Is SRI needed for resources from the same origin?

Technically is not required because same-origin resources are already trusted. However, SRI is still useful to: Detect accidental file changes, Ensure correct version in CI/CD, Defense-in-depth if the server is compromised. Many teams use SRI for all resources.

How to update SRI when the library updates?

When updating the library version, you must regenerate the SRI hash because the file content changes. Workflow: Update URL with new version, Generate new SRI hash, Update integrity attribute. Many build tools (webpack-subresource-integrity, vite) automatically generate SRI. Or use lockfile to pin exact versions.

Related keywords

sri hash generatorsubresource integrityintegrity hash generatorcdn securityscript integritysha384 hash generatorweb securitysupply chain securitycrossorigin anonymouscdn integrity check

Cooperate immediately with Mavis Digital

We not only design websites, but also help businesses build strong digital brands. Providing comprehensive website design services from design to SEO optimization. Please contact Mavis Digital immediately to create breakthrough, effective and sustainable technology solutions for your business in Ho Chi Minh.

Tools Security Tools related