Skip to content

Instantly share code, notes, and snippets.

@falsecz
Created February 19, 2014 15:56
Show Gist options
  • Save falsecz/9094920 to your computer and use it in GitHub Desktop.
Save falsecz/9094920 to your computer and use it in GitHub Desktop.
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