Created
July 2, 2014 17:16
-
-
Save whargrove/57545622bffec5f669db 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
require 'openssl' | |
require 'base64' | |
def gather_args | |
args = Array.new | |
# Only accepts two arguments | |
raise if ARGV.length > 2 | |
ARGV.each do |a| | |
args << a | |
end | |
puts "----- Printing Arguments -----" | |
puts "> secret: #{args[0]}" | |
puts "> base_string: #{args[1]}" | |
return args | |
end | |
def create_hash(key, data) | |
digest = OpenSSL::Digest.new('sha1') | |
return OpenSSL::HMAC.hexdigest(digest, key, data) | |
end | |
def base_64_encode(hmac) | |
return Base64.encode64(hmac) | |
end | |
args = gather_args | |
hmac = create_hash(args[0], args[1]) | |
puts base_64_encode(hmac) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment