mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +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.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);
|
||||
|
|
Loading…
Reference in a new issue