Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Add PKCS#7 padding

by burgerc (Novice)
on Dec 17, 2013 at 16:59 UTC ( #1067502=perlquestion: print w/replies, xml ) Need Help??
burgerc has asked for the wisdom of the Perl Monks concerning the following question:

I have a program listed below that encrypts some data, that will be decrypted on a .net machine. It appears that I'm performing PKCS#5 padding and .net will only except PKCS#7 padding. I'm looking for a sub routine that will perform PKCS#7 padding or any help in getting this to encrypt with PKCS#7 padding. Thanks in advance for any help with this.
#!/usr/local/bin/perl -w use Crypt::Rijndael; use Crypt::CBC; use MIME::Base64; use Encode; my $venture_aes_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; my $venture_iv_key = "KKKKKKKKKKKKKKKK"; my $PORTAL_ACCTNUM = "0123456789"; my $string = decode("UTF-8", $PORTAL_ACCTNUM); my $us = encode("UTF-16le", $string); my $AES_cipher = Crypt::CBC->new({ key => $venture_aes_key, # 256 bits cipher => "Crypt::Rijndael", iv => $venture_iv_key, # 128 bits literal_key => 1, padding => "standard", blocksize => 16, header => "none", keysize => 32 # 256/8 }); ## Encrypt Data my $encrypted_acctnum = $AES_cipher->encrypt($us); $encoded = encode_base64($encrypted_acctnum, ''); print $encoded; exit; }

Replies are listed 'Best First'.
Re: Add PKCS#7 padding
by Anonymous Monk on Dec 17, 2013 at 19:26 UTC
    PKCS#7 padding is just a generalization of PCKS#5 padding to allow for block sizes other than 8 bytes. I don't the padding is the problem.
      A .net server is doing the decrypting and it specifies that it must be pkcs#7. I understand there should be no difference, and my program can decrypt my string and the .net string, however .net can not. Probably doesn't mean anything but here are the two encrypted strings.

      .net with pkcs#7 - Toi0YpovwX79oXK105RzcH28XjJoxy8Y2q+R1LHyNiw=

      perl with pkcs#5 - KBjT88Hk9MBtacub+xT54g==

      both of these decrypt to the same string.

      If I'm wrong please let me know.

      I appreciate your help Chris

        So... any idea why the .net version is twice as long? Are you sure your perl script decodes them both to the same thing? Have you tried printing the result with MIME::QuotedPrint to see if there are any weird nonprinting characters in there?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1067502]
Approved by Eliya
and the questions are moot...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2018-04-24 01:58 GMT
Find Nodes?
    Voting Booth?