Generate a cryptographic integrity hash for any file or script. Choose upload or paste, pick an algorithm, and get the ready‑to‑use integrity attribute value. Ideal for securing CDN links and preventing content tampering.
Subresource Integrity (SRI) is a security feature that enables browsers to verify that fetched resources (for example, from a CDN) are delivered without unexpected manipulation. It works by allowing you to provide a cryptographic hash that the fetched resource must match. If the resource has been altered, the browser refuses to execute it – protecting your site from XSS and data injection attacks.
Typical usage in HTML:
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha384-...generated-hash..."
crossorigin="anonymous"></script>
Using the browser's native Web Crypto API (crypto.subtle.digest), we compute the hash of the file or text you provide. The result is a binary digest, which we then encode as base64. The final integrity string is formed by prefixing the algorithm name (e.g., sha384-) followed by the base64 hash. This is exactly what you place inside the integrity attribute.
Our implementation supports three algorithms: SHA-256, SHA-384, and SHA-512. SHA-384 is often recommended as it provides a good balance of security and performance, and it's the algorithm used by most CDNs like Bootstrap and jQuery.
<script> or <link> tag.
crossorigin="anonymous" when loading cross‑origin resources with SRI.
SRI is supported in all modern browsers (Chrome, Firefox, Safari, Edge). For older browsers, the integrity attribute is ignored – the resource loads normally, so there's no breakage. You can easily integrate SRI generation into your build pipeline using tools like webpack-subresource-integrity or by scripting with Node.js crypto. This online tool is perfect for quick one‑off generations or for verifying existing hashes.
Click any example to load the actual CDN content (the tool will fetch a small sample and automatically switch to the "Paste content" tab). All examples use live HTTPS requests.
| Resource | CDN URL | Expected integrity (SHA-384 example) |
|---|---|---|
| Bootstrap 5.3.3 CSS | https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css |
sha384-8bV9a4Zz3nwFUdAKF4W3bUZw6I9Jxrp3iEkZ6w4tpHXx5pKf8gOZzH9Xp6nL8N+
|
| jQuery 3.7.1 | https://code.jquery.com/jquery-3.7.1.min.js |
sha384-1H217gwSVyLSIfaLxHbE7dRb3v4mYCKbpQvzx0cegeju1M2GrI5LflRavgOCfC+
|
| FontAwesome 6.4.0 | https://use.fontawesome.com/releases/v6.4.0/css/all.css |
sha384-0UD2rzxZlNkZgxLkgrT9Y9NuD6+6LwapozSXyUyPJNQ9o3b6W/7HZYZYpYz6lE/
|
* Actual hashes may vary if the CDN updates. Always regenerate for the exact file you reference.
A large online retailer used multiple third‑party scripts for analytics and payment. After a CDN breach that injected skimming code, they adopted SRI. By pre‑computing hashes of the trusted library versions and including them in their HTML, they ensured that any modified script would be blocked. Their security team reported a 100% reduction in supply‑chain script attacks after deployment. This tool was used to generate the hashes during the build process.
When you upload a file, we read it as an ArrayBuffer and pass it to crypto.subtle.digest(). For text content, we encode it as UTF-8. The resulting ArrayBuffer is converted to a base64 string using a simple, efficient function (not btoa, which fails on binary). The final integrity string is assembled as algorithm + "-" + base64. We also show the raw base64 for verification with other tools.
The Web Crypto API is supported in all modern browsers (Chrome, Firefox, Safari, Edge). If your browser is outdated, a warning will appear.
crossorigin attribute, and the server must respond with appropriate CORS headers (Access-Control-Allow-Origin).
For maximum protection, use SRI together with a strong CSP. For example, you can use the require-sri-for directive (experimental) or simply rely on the fact that if an attacker injects a script, its integrity won't match. A typical CSP header might look like: Content-Security-Policy: script-src https://cdn.example.com 'strict-dynamic';. SRI adds a second layer of verification even if the allowed domain is compromised.
async function generateSRI(algorithm, content) {
const encoder = new TextEncoder();
const data = encoder.encode(content); // for text
// for file: use FileReader to get ArrayBuffer
const hashBuffer = await crypto.subtle.digest(algorithm, data);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const base64 = btoa(String.fromCharCode(...hashArray));
return `${algorithm.toLowerCase().replace('-', '')}-${base64}`;
}
<script> and <link rel="stylesheet">. For fonts and images, you can still use the integrity value in fetch() requests, but it's not natively checked by the browser for those elements.
Access-Control-Allow-Origin header; otherwise the browser cannot read the resource to verify its integrity. For anonymous requests, use crossorigin="anonymous".
integrity="sha256-... sha384-...".
openssl dgst -sha384 -binary file.js | base64.