I need to send an encrypted code to a web server where it will be decrypted with a java script. I have a script that creates the token and another that can decrypt it. The problem is when I send it to the java script, it throws an exception because of the padding. PKCS#5 pads with the number of bytes that should be truncated. So, if blocksize is 8, then "0A0B0C" will be padded with "05", resulting in "0A0B0C0505050505". If the final block is a full block of 8 bytes, then a whole block of "0808080808080808" is appended. In my script I can pad with nulls but how would I do PKCS#5? If someone could rewrite this (even using Crypt::CBC) and get the 32 character token with the correct padding, I would be forever grateful
In my haste to post the code, I didn't complete the scrubbing. I've made the corrections.
#!/usr/bin/perl
use Crypt::Rijndael;
my $key = "1A2B3C4D5E6FA1B2C3D4E5F61A2B3C4D";
$key = pack("H*",$key);
$crypt = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_ECB() );
my $vers = 1;
my $rand = 1002247;
my $time = 1317072992;
my $empid = 123;
my $sum = 103;
$packed = pack( "CLLLC", $vers, $rand, $time, $empid, $sum );
my $token = $crypt->encrypt($packed^("\0"x16));
$token = unpack("H*",$token);
print "---------+---------+---------+--\n";
print $token,"\n";
exit;