-
-
Save elis/892ebac9d078733fbc3dd02a4afb0379 to your computer and use it in GitHub Desktop.
Node.JS - CRYPTO How to sign a file
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
//how to execute: node sign.js <path file> <path private key> | |
//output: signature of file | |
var crypto = require('crypto'); | |
var fs = require('fs'); | |
var args = process.argv.slice(2); | |
var fileName = args[0]; | |
var keyPath = args[1]; | |
//openssl genrsa -out key.pem 1024 | |
var privatePem = fs.readFileSync(keyPath); | |
var key = privatePem.toString(); | |
var sign = crypto.createSign('RSA-SHA256'); | |
var buffer = fs.readFileSync(fileName); | |
sign.update(buffer); | |
var sig = sign.sign(key, 'hex'); | |
console.log(sig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment