Last active
August 29, 2015 13:56
-
-
Save NZKoz/8968692 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
def gimme_yo_stuff | |
time = Time.now.httpdate | |
YOUR HTTP LIBRARY.GET(path, :headers=> { | |
"Accept" => ACCEPT, | |
"Date"=>time, | |
"Authorization"=>"#{@key_id}:#{signature_for_path(path, 'GET', time)}" | |
}) | |
end | |
def signature_for_path(path, method, time) | |
payload = string_to_sign(method, path, time) | |
digest = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret, payload) | |
# this nonsense is base64 encoding, you may or may not have to remove the \n from your | |
# digests, depends how your library works | |
[digest].pack('m').gsub("\n", '') | |
end | |
def string_to_sign(method, path, time) | |
[method, HOST, path, time, @key_id, ACCEPT, ''].join("\n") | |
end |
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
>>> payload = 'lulz' | |
>>> import hashlib | |
>>> import hmac | |
>>> import base64 | |
>>> h = hmac.new("YOUR SECRET", payload, hashlib.sha256) | |
>>> h = hmac.new("YOUR SECRET", payload, hashlib.sha256) | |
>>> d = h.digest() | |
>>> base64.b64encode(d) | |
'AKdJyTNPtw+rFru9gl/pb6Wf5OBu/12ycZN/i+quCyU=' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment