• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JCE, AES and Padding

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
New to the JCE. I have some code that encrypts and decrypts some strings.
It works nothing to hard and no in depth knowledge of cryptographical techniques need, not sure if i should take teh credit of JCE should

However I am testing my class, and was trying to force the decryption method to throw a bad padding exception. This I managed, but i dont understand how or why.

I defined my Algorithm as AES, does AES have a default padding scheme or is the default no padding? (Have a feeling it is no padding as default).
I have read that the default block size is 8 bytes for AES, however the array of byte I gave it to decode was 8 bytes long.

any help and insight would be greatly welcomed.

Thanks
Gavin
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not quite following. You have code that encrypts and decrypts just fine. Then you changed something on purpose so that it throws a BadPaddingException, and now you're wondering why it does that? What did you change in the code?
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, to have confused.
I am unit testing.
So I have not changed anything in the code, I simple gave the Cipher i had set up to do decryption an array of 16 bytes.

 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For crypto, messages typically must be padded to an integral number of bits to fill the block using http://www.rfc-archive.org/getrfc.php?rfc=3852
RFC 3852 - Cryptographic Message Syntax (CMS) Section 6.3

This is also sometimes refered to as PKCS7

If you want real overkill, google for OAEP

With RFC3852, blocks are padded to always end with a byte with the number of pad characters. So in a 16 byte initial block, you get a second block of all padding. Whereas a 15 byte block would only get one byte of padding.
reply
    Bookmark Topic Watch Topic
  • New Topic