in reply to Re^2: Decrypting BlowfishNET (was Re^11: line by line Encryption ...)
in thread line by line Encryption fun with Crypt::CBC and Rijndael? File Ownership issues?

Please put <c>...</c> around your long data line! (And please include a newline within those tags.)


The data size doesn't jive.

The cipher text, once base64 decoded, is 576 ( 72*8 ) bytes long.
Your plain text is 550 ( 68*8+6 ) bytes long.
Your padded plain text is 552 ( 69*8 ) bytes long.
The IV is 8 bytes long.
There are 16 ( 576-(552+8) ) unaccounted bytes

Unless the CRLF is used for line endings.

The cipher text, once base64 decoded, is 576 ( 72*8 ) bytes long.
Your plain text is 560 ( 70*8+0 ) bytes long.
Your padded plain text is 568 ( 71*8 ) bytes long.
The IV is 8 bytes long.
There are 0 ( 576-(568+8) ) unaccounted bytes

At least your Java code outputs as many bytes as expected.


The following should produce the plain text.

use strict; use warnings; use Crypt::CBC qw( ); use List::MoreUtils qw( apply ); use MIME::Base64 qw( decode_base64 ); my $key = 'Abcdefghijklmnopqrstuvwxyz1234567890'; my $ctext = decode_base64(apply { s/\s//g } <<'__EOI__'); mGWcw1XJV3ooXbGvzBuShOA2gwcUnW11NZnHm1Nm 8JQktRSoaAKl369jL8ZLnJNF71I5ctZq8wGGtfov iLj6PoXZWlzcasgBBUMefjGa0h+L53/VODmqCDaL 6jnZycB5VTngY5gt/9VpYxVW0KB5yR0TJrhHQa02 Vgn1I9ePtmbJfOkALXZPwY0H8MDULkzIYX409iSm 6zgu76UvW81qpJiakFDi9jmIbL4NVWYRlVR1xLRC HiM8X8q0yCT1ZQO9HJE8vHc/jKdEOi8QGNyAOtdd ku7Ikg4Pzwpk7g+R/TOCx7Q8xDKbV93sFHu1s3co pZrpCcNmd8Oy1CFazZ5FweWwsFqfgxMqopMrtaG6 Qc1J7cB3fYpI2RDN6xbAJ8HPZWGdOQsobopv+Czt GFuzVaVfwz8YXrLEXlbRFfv8Cpt8Q320NAAhwjFj eEUMyPCpzVZaBske4NDJ++7JomijlS8H8cHmmD6P Hbopy41W8BF9tsV9nqXgYeiVna98MNTEkyToyP/Z kBhGYJcutv3s9pG7SydwuKCxCd+Dugusnu8lM10/ 5UmGJ7YTGFCJvtfpXR9XoMCQ++eT4/YN9kZlim+2 bkjh01xPnG9r7PChWAVxpUVjOisGlZKrPV6tQRPU qwQ0die7XienUt5e+jACACGMqXWA4O8P5sg/iT3w Z2+dDIQiUnxCIATKn74/B8V9PDdtHnr5XOP5KPKK aYcz/gXt1Q6WkWawUIoLvCkobkm5o7MXeAiJCtet emfA86bV __EOI__ my $blksz = 8; # Chicken-egg UI problem with Crypt::CBC. my $iv = substr($ctext, 0, $blksz, ''); my $cipher = Crypt::CBC->new( -cipher => 'Blowfish', -key => $key, -header => 'none', -iv => $iv, ); binmode(STDOUT); print($cipher->decrypt($ctext));

...But it doesn't. I'll have to study how the key is used by both libraries. Or maybe it's some byte ordering problem? But I don't think so from what I've seen.


Your padding method could be problematic. You use
byte fill = (byte)mod;           while (i < len) { inBuf[i++] = (byte)fill; }
but Crypt::CBC expects
byte fill = (byte)(len-origLen); while (i < len) { inBuf[i++] = (byte)fill; }