Skip to content

Instantly share code, notes, and snippets.

@em
Created November 16, 2011 02:42
Show Gist options
  • Save em/1369103 to your computer and use it in GitHub Desktop.
Save em/1369103 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Example: ./gensig 0 0123456789ABCDEF0123456789ABCDEF "[0,transactioncreate,[account_code:testac,amount_in_cents:5000,currency:USD]]"
require 'openssl'
@timestamp = ARGV[0]
@private_key = ARGV[1]
def generate_signature(input_string, timestamp=nil)
timestamp ||= Time.now.to_i
timestamp = timestamp.to_s
digest_key = ::Digest::SHA1.digest(@private_key)
sha1_hash = ::OpenSSL::Digest::Digest.new("sha1")
signature = ::OpenSSL::HMAC.hexdigest(sha1_hash, digest_key, input_string.to_s)
signature + '-' + timestamp
end
puts 'signature: %s' % generate_signature(ARGV[2], @timestamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment