2

I'm creating an AES key using the KeyGenerator class. Then I exposed a web service to do encryption and decryption using this AES key and return the cipher text/plain text in web service response.

Encryption is working perfectly fine but when I call the web service (from SOAP UI) for decryption, I'm getting javax.crypto.BadPaddingException: Given final block not properly padded exception intermittently.

I'm using hexadecimal (using the org.apache.commons.codec.binary.Hex class) encoding/decoding to convert bytes in to String and vice versa.

I created a standalone class to test this code and working without any issues.

Any thoughts on how to resolve this issue?

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
user3817206
  • 315
  • 4
  • 14
  • 2
    Please show the relevant code for your issue, without it we can't give you much. – initramfs Jul 08 '14 at 16:20
  • BadPaddingException questions here fall into one or more of the following categories: 1) using different keys or IVs for encryption and decryption 2) using lossy encoding for passing encrypted data (think of `String.getBytes()`, especially without specifying encoding) 3) using `InputStream` on decrypting side and ignoring the return value of `read()` method. Which category is this question, I wonder. – Oleg Estekhin Jul 08 '14 at 18:48
  • @OlegEstekhin I would bet on stream handling... But the user does not seem to respond anymore. – Maarten Bodewes Jul 13 '14 at 11:11

0 Answers0