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)
Terms Of Use | Privacy Statement | Company info
  • © Cedac Sistemi srl
  • Head office: Via Toscana, 3 40035 Castiglione dei Pepoli (Italy) Tel.: +39 0534-93811 Fax: +39 0534-93899
  • Branch office: Via del Lavoro, 47 40033 Casalecchio di Reno (Italy)
  • Branch office: Via Parini, 1 40033 Casalecchio di Reno (Italy)
  • Share capital Euro 26,000.00 - Company Register of Bologna / VAT no / fiscal code 01695261204