AZ Tools

CSP Hash Generator

Network

Paste the exact contents of an inline script or style (no <script> tags, no leading/trailing whitespace differences) and the tool computes the SHA-2 digest over its UTF-8 bytes, base64-encodes it, and emits the 'sha256-…' style token that CSP accepts as a whitelist entry. The browser hashes the same way at parse time, so any byte mismatch — including line endings — will fail to match and the block will not execute. Use this instead of 'unsafe-inline' when you really do need a tiny inline snippet.

Algorithm
Target directive

Paste something to hash.

The browser hashes the exact bytes of the inline element. Whitespace, indentation, and line endings all count.

How to use

  1. Paste the script body (everything between <script> and </script>) or the style body.
  2. Pick the algorithm (sha256 is enough for almost everyone; 384/512 if your policy mandates them).
  3. Copy the resulting 'sha256-…' token into the right -src directive.

Frequently asked questions

Whitespace and newlines matter?
Yes — the browser hashes the literal bytes of the element. A trailing newline or a different indentation will invalidate the hash. Paste exactly what's between the tags.
Should I always use sha512?
No. sha256 is the de-facto baseline; sha384/sha512 are only required if your policy or auditor specifies them. Longer digests don't add real security here — the threat model assumes the inline content is what you authored.

Related tools