Last active
January 11, 2023 15:44
-
-
Save ajinabraham/746d3bceb26b8aff9be4d871da61fb9f to your computer and use it in GitHub Desktop.
Node.js Digital Signature - Sign
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
//Create Private Key with OpenSSL | |
//openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -pkeyopt rsa_keygen_pubexp:3 -out privateKey.pem | |
//Generate Public Key to be used at the client side (Mobile) | |
//openssl pkey -in privateKey.pem -out publicKey.pem -pubout | |
const crypto = require('crypto') | |
const fs = require('fs') | |
const private_key = fs.readFileSync('digital_sign/privateKey.pem', 'utf-8') | |
//File to be signed | |
const package = fs.readFileSync('webpackage.zip') | |
//Signing | |
const signer = crypto.createSign('sha256'); | |
signer.update(package); | |
signer.end(); | |
const signature = signer.sign(private_key) | |
const buff = new Buffer(signature); | |
const base64data = buff.toString('base64'); | |
console.log('Digital Signature: ' + base64data); | |
//Equivalent to openssl dgst -sha256 -sign digital_sign/privateKey.pem webpackage.zip | base64 |
i keep getting browser not suported
Could I sign a pdf file and include a placeholder within the document with this code/ crypto module?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://imadeit-davidjanes.tumblr.com/post/144906098561/nodejs-crypto-signing-and-verifying-messages