Skip Menu |

This queue is for tickets about the Crypt-CBC CPAN distribution.

Report information
The Basics
Id: 41151
Status: resolved
Priority: 0/
Queue: Crypt-CBC

People
Owner: LDS [...] cpan.org
Requestors: sbest [...] echogent.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: possible bug with padding
Date: Sat, 22 Nov 2008 15:53:18 -0800
To: bug-Crypt-CBC [...] rt.cpan.org
From: Scott Best <sbest [...] echogent.com>
Heya. Am trying to decrypt an AES-128-CBC message received from another platform which uses no padding. The script I'm using is attached below. Problem is: I cannot seem to turn off padding, even with the "rijndael_compat" option. The input is 16B, the key is 16B, the IV is 16B, but the result is 32B. Script output is: IV used: 00000000000000000000000000000000 Padding used: CODE(0x81d912c) Encrypted hex is: 0a234d17985d5bc8818ff6965d894072a389b2719ddc045eaf808b571e3072a7 Expected: 0a234D17985D5BC8818FF6965D894072 Thanks in advance for any help! -Scott Show quoted text
----------start------------------ #!/usr/bin/perl use Crypt::CBC; use MIME::Base64; use bytes; ### set key in hex; pack a 32-character hex string into 16B # #my $hexkey = "7a697070657236373839616263646566"; my $hexkey = "E5E6E7E9EA292A2B2D256789012345E5"; my $key = pack 'H*',$hexkey; print "Key size is: ", bytes::length($key), " bytes\n"; ### set IV to all-zeroes; pack a 32-character hex string into 16B # my $hexiv = "00000000000000000000000000000000"; my $iv = pack 'H*',$hexiv; print "IV size is: ", bytes::length($iv), " bytes\n"; ### Plaintext is 16-characters of ASCII, 16-bytes # my $plaintext = "Hello world!!!!!"; print "Plaintext size is: ", bytes::length($plaintext), " bytes\n\n"; ### Options are critical: literal key, keysize, specify IV # my $cipher = Crypt::CBC->new( -key => $key, -header => 'none', -literal_key => 'true', -iv => $iv, -cipher => 'Rijndael', -keysize => '16', -blocksize => '16' -padding => 'rijndael_compat' ); ### Perform encryption here # my $ciphertext = $cipher->encrypt($plaintext); ### Printout IV and padding, just to be sure... # my $usediv = $cipher->get_initialization_vector(); my $divhex = unpack 'H*',$usediv; print "IV used: ", $divhex, "\n"; print "Padding used: ", $cipher->padding(), "\n\n"; ### Printout 16B result, converted into 32 Hex digits # my $cipherhex = unpack 'H*',$ciphertext; print "Encrypted hex is: ", $cipherhex, "\n"; print "Expected: 0a234D17985D5BC8818FF6965D894072","\n"; ### Encode binary result using base64: # my $b64_enc = encode_base64($ciphertext); print "B64 encoded hex is: ", $b64_enc, "\n" ; ### Finally, decode base64 string, then decrypt it: # my $b64_dec = decode_base64($b64_enc); my $decrypted = $cipher->decrypt($b64_dec); print "Decrypted result is: ", $decrypted, "\n"; ----------end-------------------------------------
Fixed in 2.31