Created
November 2, 2012 07:33
-
-
Save matthiasg/3999277 to your computer and use it in GitHub Desktop.
sign and verify
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
#!/bin/bash | |
ssh-keygen -f $1 -b 1022 -q | |
ssh-keygen -e -f $1.pub -m PEM > $1.pem |
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
$ ./generate.sh beep | |
Enter passphrase (empty for no passphrase): | |
Enter same passphrase again: | |
$ node sign.js | |
KXJe7//FttpCILzQFfZs5xWu55DzQT8sYJ+q0r775fTSvlFjgs51EFOu3oLouAKZtVygQ7Je1uGxeJ62GZY0H7a0GD9zYPVrSatdWSHDFl7udeZdlyaePJNhM0TSBXQOxeAydoUMaolgajkLFz32Znl4JnMmx0BD0BewsMayWQI= | |
true | |
$ |
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 crypto = require('crypto'); | |
var fs = require('fs'); | |
var key = { | |
priv : fs.readFileSync(__dirname + '/beep'), | |
pub : fs.readFileSync(__dirname + '/beep.pem'), | |
}; | |
var signer = crypto.createSign('RSA-SHA1'); | |
signer.update('beep boop'); | |
var s = signer.sign(key.priv, 'base64'); | |
console.log(s); | |
var v = crypto.createVerify('RSA-SHA1') | |
.update('beep boop') | |
.verify(key.pub, s, 'base64'); | |
; | |
console.log(v); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment