Skip to content

Instantly share code, notes, and snippets.

@cleishm
Created June 22, 2012 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleishm/2973636 to your computer and use it in GitHub Desktop.
Save cleishm/2973636 to your computer and use it in GitHub Desktop.
Generate timestamped signature
#!/usr/bin/env ruby
require 'digest/md5'
require 'base64'
if ARGV.length != 1
$stderr.puts "usage: #{$0} secret"
exit 1
end
timestamp = Time.now.to_i
key = [timestamp, ARGV[0]].pack('NZ*')
hash = Digest::MD5.digest(key)
signature = [timestamp, hash].pack('NZ16')
$stdout.puts Base64.urlsafe_encode64(signature).sub(/=+$/, '').chomp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment