mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-04 19:45:59 +01:00
UnlockSecretKey: Do not try to get decryptor for unencrypted keys
This commit is contained in:
parent
73f6c54fa2
commit
ce4869e15a
1 changed files with 5 additions and 1 deletions
|
@ -20,6 +20,7 @@ import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||||
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
|
||||||
import org.pgpainless.exception.WrongPassphraseException;
|
import org.pgpainless.exception.WrongPassphraseException;
|
||||||
|
import org.pgpainless.key.info.KeyInfo;
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
|
|
||||||
public class UnlockSecretKey {
|
public class UnlockSecretKey {
|
||||||
|
@ -27,7 +28,10 @@ public class UnlockSecretKey {
|
||||||
public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector)
|
public static PGPPrivateKey unlockSecretKey(PGPSecretKey secretKey, SecretKeyRingProtector protector)
|
||||||
throws WrongPassphraseException {
|
throws WrongPassphraseException {
|
||||||
try {
|
try {
|
||||||
PBESecretKeyDecryptor decryptor = protector.getDecryptor(secretKey.getKeyID());
|
PBESecretKeyDecryptor decryptor = null;
|
||||||
|
if (KeyInfo.isEncrypted(secretKey)) {
|
||||||
|
decryptor = protector.getDecryptor(secretKey.getKeyID());
|
||||||
|
}
|
||||||
return secretKey.extractPrivateKey(decryptor);
|
return secretKey.extractPrivateKey(decryptor);
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
throw new WrongPassphraseException(secretKey.getKeyID(), e);
|
throw new WrongPassphraseException(secretKey.getKeyID(), e);
|
||||||
|
|
Loading…
Reference in a new issue