Created
November 13, 2012 19:57
-
-
Save DmZ/4067998 to your computer and use it in GitHub Desktop.
Simple S3 signing for expiring URLs (Ruby)
This file contains 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 | |
require 'time' | |
require 'uri' | |
require 'cgi' | |
require 'base64' | |
require 'openssl' | |
expires = Time.now().to_i + Integer(ARGV[0]) | |
url = URI.parse(ARGV[1]) | |
access_key = ENV["AWS_ACCESS_KEY_ID"] | |
secret_key = ENV["AWS_SECRET_ACCESS_KEY"] | |
h = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, | |
secret_key, | |
"GET\n\n\n#{expires}\n#{url.path}") | |
sign = CGI::escape(Base64.encode64(h).strip) | |
print "#{ARGV[1]}?AWSAccessKeyId=#{access_key}&Expires=#{expires}&Signature=#{sign}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment