Fixed NPE in decrypt by passing in empty char[]

This commit is contained in:
hierynomus
2015-01-20 09:34:12 +01:00
parent 83c5f2f815
commit a95fad89a0

View File

@@ -139,7 +139,9 @@ public class PKCS8KeyFile
JcePEMDecryptorProviderBuilder decryptorBuilder = new JcePEMDecryptorProviderBuilder();
decryptorBuilder.setProvider("BC");
try {
passphrase = pwdf == null ? null : pwdf.reqPassword(resource);
// Do not return null, as JcePEMDecryptorProviderBuilder$1$1.decrypt would throw an exception
// in that case because it requires a 'password' (i.e. passphrase).
passphrase = pwdf == null ? "".toCharArray() : pwdf.reqPassword(resource);
kp = pemConverter.getKeyPair(encryptedKeyPair.decryptKeyPair(decryptorBuilder.build(passphrase)));
} finally {
PasswordUtils.blankOut(passphrase);