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;

In reply to 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.