Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.