Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Encrypt and Decrypt

28 views
Skip to first unread message

Bhimashankar

unread,
Aug 17, 2009, 8:36:29 AM8/17/09
to herei...@gmail.com
Hi All,
Please help me to resolve the follwing the exception while Encrypt and
Decrypt the

javax.crypto.IllegalBlockSizeException: Input length must be multiple
of 8 when decrypting with padded cipher
at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)
at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)

Andreas Leitgeb

unread,
Aug 17, 2009, 9:32:33 AM8/17/09
to

If *de*crypting fails, mentioning a wrongly-sized input, then
something went wrong with gathering the crypted data or passing
it to the decrypter.

If you read in the data from a file, perhaps some kind of
conversion was applied to it (e.g. CrLf->Lf) or some extra
encoding that was applied on the crpto-text (e.g. base64)
wasn't undone before decrypting.

An "sscce" (<http://sscce.org/>) would surely help *you* (by
allowing us to spot the error in your code). But even just
an excerpt of your code may suffice, if you happen to post
the right excerpt (the one that actually contains the bug).

Roedy Green

unread,
Aug 17, 2009, 10:05:48 AM8/17/09
to
On Mon, 17 Aug 2009 05:36:29 -0700 (PDT), Bhimashankar
<bank...@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>javax.crypto.IllegalBlockSizeException: Input length must be multiple
>of 8 when decrypting with padded cipher

see:
http://mindprod.com/jgloss/runerrormessages.html#ILLEGALBLOCKSIZEEXCEPTION
--
Roedy Green Canadian Mind Products
http://mindprod.com

"If you think it�s expensive to hire a professional to do the job, wait until you hire an amateur."
~ Red Adair (born: 1915-06-18 died: 2004-08-07 at age: 89)

rossum

unread,
Aug 17, 2009, 12:44:03 PM8/17/09
to
On Mon, 17 Aug 2009 05:36:29 -0700 (PDT), Bhimashankar
<bank...@gmail.com> wrote:

Assuming that you are using a block cypher in CBC mode, then your
input plaintext will be padded to a whole number of blocks. This
means that your cyphertext will be longer than the original plaintext.
If you leave off the extra cyphertext then you will get the error you
are seeing. I suggest you check that a) you are getting all of the
cyphertext from the encrypt method and b) you are passing all of the
cyphertext to the decrypt method. It is a mistake to assume that the
cyphertext is the same length as the plaintext.

I note that you are using a 64 bit (=8 byte) block cypher, probably
DES or 3DES. Unless you absolutely need to use these for backwards
compatibility then you should use AES (32 bit/16 byte) instead. Both
DES and 3DES are obsolete.

rossum

Arne Vajhøj

unread,
Aug 22, 2009, 7:23:38 PM8/22/09
to
rossum wrote:
> On Mon, 17 Aug 2009 05:36:29 -0700 (PDT), Bhimashankar
> <bank...@gmail.com> wrote:
>> Please help me to resolve the follwing the exception while Encrypt and
>> Decrypt the
>>
>> javax.crypto.IllegalBlockSizeException: Input length must be multiple
>> of 8 when decrypting with padded cipher
>> at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)
>> at com.sun.crypto.provider.SunJCE_h.b(DashoA12275)
> Assuming that you are using a block cypher in CBC mode, then your
> input plaintext will be padded to a whole number of blocks. This
> means that your cyphertext will be longer than the original plaintext.
> If you leave off the extra cyphertext then you will get the error you
> are seeing.

I would say that the padding depends on padding not on mode.

Arne

rossum

unread,
Aug 23, 2009, 4:50:40 AM8/23/09
to
On Sat, 22 Aug 2009 19:23:38 -0400, Arne Vajhøj <ar...@vajhoej.dk>
wrote:

The amount of padding may depend on the mode. CBC mode requires one
whole block or less of padding. CTR mode requires no padding at all.

The padding spec determines the content of the padding.

rossum

0 new messages