Created
November 8, 2018 03:44
-
-
Save Dviejopomata/c87078b9a1170732358cea2ed504d30c to your computer and use it in GitHub Desktop.
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
const crypto = require("crypto") | |
const fs = require("fs") | |
const sign = crypto.createSign("SHA256") | |
const text = "hello world" | |
// openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 | |
const privateKey = fs.readFileSync("./key.pem") | |
const publicKey = fs.readFileSync("./cert.pem") | |
const passphrase = "123456" | |
sign.update(text) | |
sign.end() | |
const signature = sign.sign({ key: privateKey, passphrase }, "hex") | |
// verify | |
const verify = crypto.createVerify("SHA256") | |
verify.update(text) | |
const ok = verify.verify(publicKey, signature, "hex") | |
console.log(ok) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment