1#!/usr/bin/perl 
2
3use strict; 
4use Crypt::Rijndael;
5use Digest::MD5 qw(md5_hex);
6
7use Test::More 'no_plan';
8
9my $class = 'Crypt::Rijndael';
10
11my $key       = 'abcdefghijklmnop';
12
13my $in_plain  = 'a' x 32;
14
15my $cipher = $class->new( $key, Crypt::Rijndael::MODE_CBC ); 
16isa_ok( $cipher, $class );
17
18$cipher->set_iv('a' x 16); 
19
20# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
21# encrypt
22diag( "-" x 50 ) if $ENV{DEBUG};
23
24my $crypt  = $cipher->encrypt( $in_plain );
25
26diag( "Plain text: [$in_plain]" ) if $ENV{DEBUG};
27diag( "Crypt text: [$crypt]" ) if $ENV{DEBUG};
28
29my $digest = md5_hex( $crypt );
30diag( "MD5 digest of crypt: [$digest]" ) if $ENV{DEBUG};
31
32# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
33# decrypt to see if we get back the same thing
34{
35diag( "-" x 50 ) if $ENV{DEBUG};
36
37my $out_plain  = $cipher->decrypt( $crypt );
38
39diag( "Crypt text: [$crypt]" ) if $ENV{DEBUG};
40diag( "Plain text: [$out_plain]" ) if $ENV{DEBUG};
41
42is( $out_plain, $in_plain, "Text comes back correctly" );
43}