Subject: | PADDING_AUTO seems broken |
The sample code will encrypt a string and than decrypt it using the same key, the outcome is truncated - as if padding was not applied. It happens when the last character in the string is the "0" (zero) character.
use strict;
use Crypt::ECB;
my $key=pack("H16","12345678");
my $cipher = Crypt::ECB->new;
$cipher->padding(PADDING_AUTO);
$cipher->cipher("DES") || die $cipher->errstring;
$cipher->key($key);
my $plaintext_id = "17108154291234550";
my $crypted_id = $cipher->encrypt($plaintext_id);
my $decrypted_id = $cipher->decrypt($crypted_id);
print $decrypted_id,"\n";
print $plaintext_id,"\n";