Created
February 19, 2014 15:56
-
-
Save falsecz/9094920 to your computer and use it in GitHub Desktop.
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
fs = require 'fs' | |
crypto = require 'crypto' | |
publicKey = fs.readFileSync './pub.pem' | |
plaintext = fs.readFileSync './plaintext' | |
cipertext = fs.readFileSync './ja.sig' | |
verify = (publicKey, text, cipher) -> | |
for h in ['rsa-sha1', 'rsa-sha1-2', 'sha1'] | |
try | |
verifier = crypto.createVerify(h.toUpperCase()) | |
verifier.update text | |
result = verifier.verify publicKey, cipher, "binary" | |
return yes if result is yes | |
catch err | |
no | |
console.log verify publicKey, plaintext, cipertext | |
------ | |
var SSHAgentClient = require('ssh-agent'); | |
var client = new SSHAgentClient(); | |
fs = require('fs'); | |
var data = fs.readFileSync('plaintext'); | |
// Try to sign data with an RSA key (will generate | |
// an RSA-SHA1 signature). | |
client.requestIdentities(function(err, keys) { | |
var key = null; | |
for (var i = 0; i < keys.length; i++) { | |
if (keys[i].type === 'ssh-rsa') { | |
key = keys[i]; | |
break; | |
} | |
} | |
if (!key) | |
return; | |
client.sign(key, data, function(err, signature) { | |
fs = require('fs'); | |
fs.writeFileSync ('ja.sig', new Buffer(signature.signature, 'base64')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment