Last active
August 29, 2015 13:56
-
-
Save wision/9096063 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' | |
SSHAgentClient = require('ssh-agent') | |
sshKeyToPEM = require 'ssh-key-to-pem' | |
client = new SSHAgentClient() | |
data = new Buffer 'mrdkaaaaaaa' | |
client.requestIdentities (err, keys) -> | |
key = null | |
for key in keys | |
if key.type is 'ssh-rsa' | |
break | |
if !key | |
return | |
client.sign key, data, (err, signature) -> | |
console.log err if err | |
cipertext = new Buffer(signature.signature, 'base64') | |
pub = 'ssh-rsa AAAA==' | |
key = sshKeyToPEM pub | |
publicKey = new Buffer key | |
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, data, cipertext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment