Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javax.crypto.BadPaddingException: pad block corrupted when BouncyCastle is on the classpath #2

Open
digulla opened this issue Jan 25, 2018 · 0 comments
Assignees
Milestone

Comments

@digulla
Copy link

digulla commented Jan 25, 2018

I'm getting javax.crypto.BadPaddingException: pad block corrupted when BouncyCastle is on the classpath at runtime but not when the license is generated.

The reason is this code:

		byte[] shortKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").
				generateSecret(keySpec).getEncoded();

in Encryptor.java which will sometimes return a factory which uses a provider from SunJCE and sometimes one which uses BC provider.

The BC provider will return a different shortKey and eventually, decryptRaw() will fail with the error above.

I don't know a workaround. A fix is to replace the code above with

		byte[] shortKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES", "SunJCE").
				generateSecret(keySpec).getEncoded();

to lock down the provider or to introduce a new System property / global config variable to select the preferred provider.

@beamerblvd beamerblvd self-assigned this Jan 22, 2019
@beamerblvd beamerblvd added this to the 2.0 milestone Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants