Bad Padding Exception - Encryption / Decryption Keys generated in different JREs
posted 4 years ago
I have a "DH" algorithm based encryption/decryption logic where, the encryption happens on client machine through an applet and the decryption happens on server component. The cryptography components that finally interact with Java Security APIs are modularized as "common" components and deployed as part of both the applet code and server side code.
Scenario 1 - The applet and the server components (including the cryptography code common to both) compiled on Java 1.6, server component running on Java 1.6, applet running on JRE 1.6 - Encryption/decryption works fine.
Scenario 2 - The applet and the server components (including the cryptography code common to both) compiled on Java 1.5, server component running on Java 1.5, applet running on JRE 1.6 - Encryption no error, decryption throws a "bad padding exception".
In both scenarios its same code, same setup only differences in Java run time as stated. Is the padding implementation different across Java 1.5 vs Java 1.6? Current padding option set is "PKCS5"
I am planning to test by setting "NoPadding" and seeing if that makes a difference. Would appreciate inputs from anyone who might have faced similar issue before.