8266293: Key protection using PBEWithMD5AndDES fails with "java.security.InvalidAlgorithmParameterException: Salt must be 8 bytes long"

Reviewed-by: valeriep
This commit is contained in:
Weijun Wang 2021-05-06 18:00:11 +00:00
parent a90b33a955
commit 04f7112647
2 changed files with 18 additions and 3 deletions

View file

@ -804,11 +804,17 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
*/
private AlgorithmParameters getPBEAlgorithmParameters(
String algorithm, int iterationCount) throws IOException {
AlgorithmParameters algParams = null;
AlgorithmParameters algParams;
byte[] salt = getSalt();
if (KnownOIDs.findMatch(algorithm) == KnownOIDs.PBEWithMD5AndDES) {
// PBES1 scheme such as PBEWithMD5AndDES requires a 8-byte salt
salt = Arrays.copyOf(salt, 8);
}
// create PBE parameters from salt and iteration count
PBEParameterSpec paramSpec =
new PBEParameterSpec(getSalt(), iterationCount);
new PBEParameterSpec(salt, iterationCount);
try {
algParams = AlgorithmParameters.getInstance(algorithm);
algParams.init(paramSpec);