Skip to content

Instantly share code, notes, and snippets.

@robcalcroft
Created May 20, 2018 22:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robcalcroft/a1ae4b3a39c4e12bfbd1bbe2b88e539f to your computer and use it in GitHub Desktop.
Save robcalcroft/a1ae4b3a39c4e12bfbd1bbe2b88e539f to your computer and use it in GitHub Desktop.
Create a sha256 hash of a string in Node.js to use in a CSP
const crypto = require('crypto');
function createSha256CspHash(content) {
return 'sha256-' + crypto.createHash('sha256').update(content).digest('base64');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment