Java Cipher - AES population issue

I use an AES cipher with a block size of 16 bytes.

If I try to encrypt a 16-byte string, I have no problem, but any other length that is not a multiple of 16 throws an exception.

I know that with 3-DES you can specify the type of padding as part of the algorithm, and it is processed without additional work (e.g. DES / CBC / PKCS5Padding), but is there any way to specify this using AES?

Or do I need to impose pytes manually on a multiple of 16, and then impose them when decrypting? The following is an example of abbreviated code.

encrypt = Cipher.getInstance("AES", provider);
encrypt.init(Cipher.ENCRYPT_MODE, key) ;
byte[] encrypted = encrypt.doFinal(plainTxt.getBytes()) ;

Answers to all and all answers!

Thanks in advance, Ciarán

+5
source share
1 answer

All Articles