Created
September 30, 2011 23:03
-
-
Save em/1255264 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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