Skip to content

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

Description

@digulla

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions