Here is a running version of your code, with a legitimate key. It takes your values, makes a token, then decrypts the token. Can you describe in more detail what you need with the padding? Here is a commonly used sub for padding. Substitute your padding for the null bytes "\0", with a similar length($data) method.
sub get16 { my $data = shift; # return "\0" x ( 16 - length($data) % 16 ) . $data; return $data . "\0" x ( 16 - length($data) % 16 ); }

Here is your code, working with a legitimate key with debugging steps along the way.

#!/usr/bin/perl use warnings; use strict; use Crypt::Rijndael; my $key = "1A2B3C4D5E6Fabcd"; #$key = pack("H*",$key); print "$key\n"; my $crypt = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_ECB() ); my $vers = 1; my $rand = 1002247; my $time = 1317072992; my $empid = 123; my $sum = 103; my $ndid = 42; my $packed = pack( "CLLLC", $vers, $rand, $time, $ndid, $sum ); print "$packed\n"; my @unpacked = unpack("CLLLC",$packed) ; print "@unpacked\n"; my $token = $crypt->encrypt($packed^("\0"x16)); print "\n$token\n"; $token = unpack("H*",$token); print "---------+---------+---------+--\n"; print $token,"\n"; # do decryption my $z = pack("H*", $token); print "$z\n"; my $cbc1 = new Crypt::Rijndael $key, Crypt::Rijndael::MODE_CBC; my $decrypted = $cbc1->decrypt($z); print "decrypted->$decrypted\n"; my @values = unpack("CLLLC",$decrypted) ; print "@values\n"; exit;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: AES/ECB/PKCS#5 encryption by zentara
in thread AES/ECB/PKCS#5 encryption by dbarstis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.