PHP sample code for the signature calculation

 

 

<?php
// Encode a string to base64
function encodeBase64Safe($value)
{
	return str_replace(array('+', '/'), array('-', '_'),
	base64_encode($value));
}

// Decode a string from base64
function decodeBase64Safe($value)
{
	return base64_decode(str_replace(array('-', '_'), array('+', '/'),
	$value));
}

// Sign a command with a given crypto key
// Note that this command must be properly encoded
function SignedCommand($itemToCheck, $privateKey)
{
	// Decode the private key into its binary format
	$decodedKey = decodeBase64Safe($privateKey);

	// Create a signature using the private key and the URL-encoded
	// string using HMAC SHA1. This signature will be binary.
	$signature = hash_hmac("sha1",$itemToCheck, $decodedKey, true);

	$encodedSignature = encodeBase64Safe($signature);

	return $encodedSignature;
}

echo SignedCommand("COMMAND_ITEM_TO_SIGN", 'YOUR_PRIVATE_KEY');
?>
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