From ce4869e15ae9564756e22227eb4add9c538977b6 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 31 May 2021 15:38:47 +0200 Subject: [PATCH] UnlockSecretKey: Do not try to get decryptor for unencrypted keys --- .../java/org/pgpainless/key/protection/UnlockSecretKey.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java b/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java index 8d47396a..421183de 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/protection/UnlockSecretKey.java @@ -20,6 +20,7 @@ import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.pgpainless.exception.WrongPassphraseException; +import org.pgpainless.key.info.KeyInfo; import org.pgpainless.util.Passphrase; public class UnlockSecretKey { @@ -27,7 +28,10 @@ public class UnlockSecretKey { public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector) throws WrongPassphraseException { try { - PBESecretKeyDecryptor decryptor = protector.getDecryptor(secretKey.getKeyID()); + PBESecretKeyDecryptor decryptor = null; + if (KeyInfo.isEncrypted(secretKey)) { + decryptor = protector.getDecryptor(secretKey.getKeyID()); + } return secretKey.extractPrivateKey(decryptor); } catch (PGPException e) { throw new WrongPassphraseException(secretKey.getKeyID(), e);