Skip to content

Instantly share code, notes, and snippets.

@wision
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wision/9096063 to your computer and use it in GitHub Desktop.
Save wision/9096063 to your computer and use it in GitHub Desktop.
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