Last active
September 16, 2019 10:22
-
-
Save katopz/18bfccd8d3513b4988306bc047f5e364 to your computer and use it in GitHub Desktop.
sha-256-js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Web : ref https://jameshfisher.com/2017/10/30/web-cryptography-api-hello-world/ | |
async function sha256(str) { | |
const buf = await crypto.subtle.digest("SHA-256", new TextEncoder("utf-8").encode(str)); | |
return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join(''); | |
} | |
// Node | |
async function sha256(str) { | |
const crypto = require('crypto') | |
const hash = crypto.createHash('sha256') | |
hash.update(str) | |
const hex = hash.digest('hex') | |
return hex | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment