RUBY sample code for the signature calculation
#!/usr/bin/ruby
require 'rubygems'
require 'base64'
# hmac, and hmac-sha1, are from # gem install ruby-hmac
require 'hmac'
require 'hmac-sha1'
def parSafeBase64Decode(base64String)
return Base64.decode64(base64String.tr('-_','+/'))
end
def parSafeBase64Encode(raw)
return Base64.encode64(raw).tr('+/','-_')
end
def signPAR(key, par)
parToSign = par
# Decode the private key
rawKey = parSafeBase64Decode(key)
# create a signature using the private key and the PAR
sha1 = HMAC::SHA1.new(rawKey)
sha1 << parToSign
rawSignature = sha1.digest()
# encode the signature into base64.
signature = parSafeBase64Encode(rawSignature)
# prepend the server and append the signature.
return signature
end
# PAR to sign
par = "COMMAND_ITEM_TO_SIGN"
# Private Key
PRIVATE_KEY = "YOUR_PRIVATE_KEY"
print signPAR(PRIVATE_KEY, par)