diff --git a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java index 2d235f5e..b41111fa 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/encryption_signing/EncryptionBuilder.java @@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; +import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.pgpainless.algorithm.CompressionAlgorithm; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.SymmetricKeyAlgorithm; @@ -353,8 +354,9 @@ public class EncryptionBuilder implements EncryptionBuilderInterface { Map privateKeys = new ConcurrentHashMap<>(); for (PGPSecretKey secretKey : signingKeys) { - privateKeys.put(new OpenPgpV4Fingerprint(secretKey), - secretKey.extractPrivateKey(signingKeysDecryptor.getDecryptor(secretKey.getKeyID()))); + PBESecretKeyDecryptor decryptor = signingKeysDecryptor.getDecryptor(secretKey.getKeyID()); + PGPPrivateKey privateKey = secretKey.extractPrivateKey(decryptor); + privateKeys.put(new OpenPgpV4Fingerprint(secretKey), privateKey); } return new EncryptionStream(