Skip to content

Instantly share code, notes, and snippets.

@whargrove
Created July 2, 2014 17:16
Show Gist options
  • Save whargrove/57545622bffec5f669db to your computer and use it in GitHub Desktop.
Save whargrove/57545622bffec5f669db to your computer and use it in GitHub Desktop.
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