Skip to content

Instantly share code, notes, and snippets.

@alexkalderimis
Created April 10, 2013 21:24
Show Gist options
  • Save alexkalderimis/5358574 to your computer and use it in GitHub Desktop.
Save alexkalderimis/5358574 to your computer and use it in GitHub Desktop.
Testing verification in ls
require! fs
require! crypto
SIG_RE = /(_|\.|-)/g
re-sig = [[\- \+], [\. \/], [\_ \=]] |> listToObj |> objToFunc
sample-response = '2!200!!20130404T013030Z!1365039030-16998-4!http%3A%2F%2Flocalhost%3A3001%2F!test0001!pwd!!36000!'
raw-sig = 'EJhXHSEuaj2T3U-f-8OMCIb2DSkFvx7jRUFY5EgGlLiyKlWcR7s1DI..FJLKGc6Otb9rKFK-haF7NvyzMMmOkbx1iKZSgUXW5B420-dW.7TPOB187xcHzQezPSw7rHxrq2byp-pRkT7G9TDWDrqAMblasSsN3s8Nanifp1gOcxA_'
sig = raw-sig.replace SIG_RE, re-sig
key = fs.readFileSync('keys/demo-server/pubkey901', \ascii)
priv-key = fs.readFileSync('keys/demo-server/privkey901', \ascii)
puts "Using key:"
puts key
ok = verify \sha1, sample-response, key, sig, \base64
puts "Signature verified: #{ ok }"
signer = crypto.createSign \sha1
..update sample-response
my-sig = signer.sign priv-key, \base64
puts "Can I sign though?"
puts "My signature:\n#{ my-sig }"
puts "which verifies: #{ verify \sha1, sample-response, key, my-sig, \base64 }"
/* helpers */
!function puts str
console.log str
function verify hash, data, pubkey, sig, enc
v = crypto.createVerify hash
..update data
v.verify pubkey, sig, enc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment