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:
parent
9587d52f29
commit
e661908c5f
1 changed files with 11 additions and 3 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue