Created
April 2, 2015 13:17
-
-
Save kalloc/5cfda6a9fea39a0f5cae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var forge = require('node-forge'); | |
console.log('start'); | |
var rsa = forge.pki.rsa; | |
console.log('gen..'); | |
// generate an RSA key pair synchronously | |
var keypair = rsa.generateKeyPair({bits: 2048, e: 0x10001}); | |
var privateKey = keypair.privateKey; | |
var publicKey = keypair.publicKey; | |
console.log('hash'); | |
var md = forge.md.sha256.create(); | |
md.update('sign this', 'utf8'); | |
console.log('pss'); | |
var pss = forge.pss.create({ | |
md: forge.md.sha1.create(), | |
mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), | |
saltLength: 20 | |
// optionally pass 'prng' with a custom PRNG implementation | |
// optionalls pass 'salt' with a forge.util.ByteBuffer w/custom salt | |
}); | |
console.log('sign'); | |
var signature = privateKey.sign(md, pss); | |
console.log('verify pss'); | |
// verify RSASSA-PSS signature | |
var pss = forge.pss.create({ | |
md: forge.md.sha1.create(), | |
mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), | |
saltLength: 20 | |
// optionally pass 'prng' with a custom PRNG implementation | |
}); | |
console.log('verify hash'); | |
var md = forge.md.sha256.create(); | |
md.update('sign this', 'utf8'); | |
var verified = publicKey.verify(md.digest().getBytes(), signature, pss); | |
console.log(signature); | |
console.log(verified); | |
console.log(pss); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment