1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 11:27:57 +01:00

Fix NPE when creating SecretKeyEncryptor for key without S2K spec

This commit is contained in:
Paul Schaub 2021-02-25 23:10:25 +01:00
parent 9587d52f29
commit e661908c5f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -60,9 +60,17 @@ public class BcImplementationFactory extends ImplementationFactory {
@Override
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase)
throws PGPException {
return new BcPBESecretKeyEncryptorBuilder(secretKey.getKeyEncryptionAlgorithm(),
getPGPDigestCalculator(secretKey.getS2K().getHashAlgorithm()),
(int) secretKey.getS2K().getIterationCount())
int keyEncryptionAlgorithm = secretKey.getKeyEncryptionAlgorithm();
if (secretKey.getS2K() == null) {
return getPBESecretKeyEncryptor(SymmetricKeyAlgorithm.fromId(keyEncryptionAlgorithm), passphrase);
}
int hashAlgorithm = secretKey.getS2K().getHashAlgorithm();
PGPDigestCalculator digestCalculator = getPGPDigestCalculator(hashAlgorithm);
long iterationCount = secretKey.getS2K().getIterationCount();
return new BcPBESecretKeyEncryptorBuilder(keyEncryptionAlgorithm, digestCalculator, (int) iterationCount)
.build(passphrase.getChars());
}