PYTHON sample code for the signature calculation

 

 

#!/usr/bin/python
# -*- coding: utf-8 -*-

import hashlib
import hmac
import base64

def sign_par(input_par=None, secret=None):

	if not input_par or not secret:
		raise Exception("Both input_par and secret are required")
	
	# Decode the private key into its binary format
	decoded_key = base64.urlsafe_b64decode(secret)
	
	# Create a signature using the private key
	# string using HMAC SHA1. This signature will be binary.
	signature = hmac.new(decoded_key, input_par.encode('utf-8'), hashlib.sha1)
	
	# Encode the binary signature into base64
	encoded_signature = base64.urlsafe_b64encode(signature.digest())
	
	# Return signature
	return encoded_signature

if __name__ == "__main__":
	input_par = "COMMAND_ITEM_TO_SIGN"
	secret = "YOUR_PRIVATE_KEY"
	print ("Signature: " + sign_par(input_par, secret).decode('utf-8'))
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