Skip to content

Instantly share code, notes, and snippets.

@MaxGraey
Last active November 12, 2016 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxGraey/b4143413fe1c59b9b333f1f374640176 to your computer and use it in GitHub Desktop.
Save MaxGraey/b4143413fe1c59b9b333f1f374640176 to your computer and use it in GitHub Desktop.
Electron signing in node.js
// 1. Generate new private RSA Key:
// openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
// 2. Derivate public RSA Key from private:
// openssl rsa -in key.pem -out public_key.pem -outform PEM -pubout
const crypto = require('crypto');
const fs = require('fs');
const hashes = crypto.getHashes();
//console.log(hashes);
var data = 'abcdef';
var privateKey = fs.readFileSync(__dirname + '/key.pem', 'ascii');
var sign = crypto.createSign('RSA-SHA256');
sign.update(data);
var signature = sign.sign(privateKey, 'base64');
console.log(signature);
var publicKey = fs.readFileSync(__dirname + '/public_key.pem', 'ascii');
var verifier = crypto.createVerify('RSA-SHA256');
verifier.update(data);
var isValid = verifier.verify(publicKey, signature, 'base64');
console.log('sign valide: ', isValid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment