Thanks for the code and explanation.
I've put the following into a stand-alone test script:
$hash_key = 'trVxrnoz22bvwvnV';
$terminal_id = '99999999';
$reference = '0000000765';
$amount = '1.23';
$data = "$hash_key$terminal_id$ref
$sha1Digest = sha1($data);
@myArray=unpack('C*', $sha1Digest);
foreach $c (@myArray)
{
$myStringHex .= "\%" . sprintf ("%lx", $c);
}
$encoded = encode_base64($myStringHex
print "$encoded\n\n";
..but get the error:
Undefined subroutine &main::sha1 called at line 10.
Any ideas?
Thanks
Main Topics
Browse All Topics





by: sedgwickPosted on 2009-11-03 at 05:10:51ID: 25728535
-> Perl interface to the SHA-1 Algorithm:
);
$data = "Ziggy is the greatest dog ever";
$sha1Digest = sha1($data);
PHP Pack() with H* formater is basically conversion of string to hexadecimal number
so to convert a scalar string to hex in Perl, check this example:
@myArray=unpack('C*', $sha1Digest);
foreach $c (@myArray)
{
$myStringHex .= "\%" . sprintf ("%lx", $c);
}
$myStringHex is the hex representation of the string.
-> MIME::Base64 - Encoding and decoding of base64 strings
$encoded = encode_base64($myStringHex