Skip to content

Instantly share code, notes, and snippets.

@alexkalderimis
Created April 10, 2013 21:22
Show Gist options
  • Save alexkalderimis/5358552 to your computer and use it in GitHub Desktop.
Save alexkalderimis/5358552 to your computer and use it in GitHub Desktop.
Verifying signature in ruby
require 'base64'
require 'openssl'
DEFAULT_PUBLIC_KEY_FILE = 'keys/demo-server/pubkey901'
RESP = '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.tr('-._','+/=')
key = IO.read( DEFAULT_PUBLIC_KEY_FILE ).to_s
puts "Verifying signature"
puts sig
puts "Using key:"
puts key
publickey = OpenSSL::PKey::RSA.new( key )
ok = publickey.verify( OpenSSL::Digest::SHA1.new, Base64.decode64(sig), RESP)
puts "Signature verified: #{ ok }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment