mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 12:52:07 +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
|
@Override
|
||||||
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase)
|
public PBESecretKeyEncryptor getPBESecretKeyEncryptor(PGPSecretKey secretKey, Passphrase passphrase)
|
||||||
throws PGPException {
|
throws PGPException {
|
||||||
return new BcPBESecretKeyEncryptorBuilder(secretKey.getKeyEncryptionAlgorithm(),
|
int keyEncryptionAlgorithm = secretKey.getKeyEncryptionAlgorithm();
|
||||||
getPGPDigestCalculator(secretKey.getS2K().getHashAlgorithm()),
|
|
||||||
(int) secretKey.getS2K().getIterationCount())
|
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());
|
.build(passphrase.getChars());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue