1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
use Test::More;
plan tests => 4;
use ExtUtils::testlib;
use Crypt::GCrypt;
my $c = Crypt::GCrypt->new(
type => 'cipher',
algorithm => 'aes', # blklen == 16
mode => 'cbc',
padding => 'standard'
);
$c->setkey('b' x 32);
{
my $text = 'a' x 999;
$c->start('encrypting');
my $t1 = substr($text, 0, 512);
my $t2 = substr($text, 512);
printf "length of original text is %d\n", length($text);
my $e = $c->encrypt($t1);
$e .= $c->encrypt($t2);
$e .= $c->finish;
printf "length of encrypted text is %d\n", length($e);
$c->start('decrypting');
my $e1 = substr($e, 0, 512);
my $e2 = substr($e, 512);
my $d = $c->decrypt($e1);
$d .= $c->decrypt($e2);
$d .= $c->finish;
printf "length of decrypted text is %d\n", length($d);
ok($d eq $text);
ok(length $d == length $text);
}
# compatibility with <= 1.17 for applications which don't call ->finish()
{
my $text = <<'EOF';
Lorem ipsum dolor sit amet, con
EOF
printf "length of original text is %d\n", length($text);
$c->start('encrypting');
my $e = $c->encrypt($text) . $c->finish;
printf "length of encrypted text is %d\n", length($e);
$c->start('decrypting');
my $d = $c->decrypt($e);
my $d2 = $c->finish; # discarding finish() output
printf "length of decrypted text is %d\n", length($d);
ok($d eq $text);
ok(length $d == length $text);
}
__END__
|