Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
[ambrus]: erix: that one actually sucks. these days people should get rid of the old notion that TeX is the only thing you can use for decent mathematics writing, because MS Office and LibreOffice have reached the
[ambrus]: level where people can more easily write as good mathematical papers in them as the people who write bad LaTeX papers usually write.
[ambrus]: Yes, for like the first twenty of its years, TeX was basically the only system that allowed you to write decent maths papers, and C++ and PHP were programming languages that sucked, etc. But times change and people have to accept that.
Discipulus bad people + good tool < normal people + decent tool
[Discipulus]: php does not suck anymore?
[ambrus]: Discipulus: I'm not sure, but it certainly doesn't suck as much as it's used to. it's like C++, it sucks because people still recursively learn from twenty year old PHP examples,
[ambrus]: and they try to use the obsolete features that PHP has to support only for compatibility with old scripts. C++ and PHP both have the problem that people can't forget the past, because when they google "PHP" plus the problme they want to solve, they find b
[ambrus]: ad code examples.
[ambrus]: I'm not trying to recommend PHP, but I think it has way too bad a name because of its past.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2017-09-26 11:06 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.