PERL sample code for the signature calculation

 

 

# Required Perl Libraries.
use Digest::HMAC_SHA1;
use MIME::Base64;

use 5.006;
use strict;
use warnings;

sub decode_parsafe_base64 {
	my($content) = @_;
	
	# replace '+' by '-', and '/' by '_'
	$content =~ tr/-/\+/;
	$content =~ tr/_/\//;
	
	return decode_base64($content);
}

sub encode_parsafe{
	my($content) = @_;
	$content =~ tr/\+/\-/;
	$content =~ tr/\//\_/;
	
	return $content;
}

sub sign_par {
	my($par) = @_;
	
	# Private Key - Replace with your private key.
	my $KEY_STRING = 'YOUR_PRIVATE_KEY';
	
	# Decode the private key into original binary format.
	my $key = decode_parsafe_base64($KEY_STRING);
	
	# Create HMAC-SHA1 Signature
	my $digest = Digest::HMAC_SHA1->new($key);
	$digest->add($par);
	
	# Encode binary signature.
	my $signature = $digest->b64digest;
	
	# Make Signature PAR safe
	$signature = encode_parsafe($signature);
	
	return ( $signature )
}

# Replace with your PAR to be signed.
my $par = "COMMAND_ITEM_TO_SIGN";

my $signed_par = sign_par($par);

print $signed_par . "\n";
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