mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +01:00
Retry key generation on invalid private key encoding length
Workaround for #70
This commit is contained in:
parent
f2f7305fec
commit
d2202dcb0f
1 changed files with 13 additions and 2 deletions
|
@ -27,6 +27,8 @@ import java.util.Iterator;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
|
@ -60,6 +62,8 @@ import org.pgpainless.util.SignatureSubpacketGeneratorUtil;
|
|||
|
||||
public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(KeyRingBuilder.class.getName());
|
||||
|
||||
private final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private final List<KeySpec> keySpecs = new ArrayList<>();
|
||||
|
@ -454,8 +458,15 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
|||
KeyPair keyPair = certKeyGenerator.generateKeyPair();
|
||||
|
||||
// Form PGP key pair
|
||||
PGPKeyPair pgpKeyPair = ImplementationFactory.getInstance().getPGPKeyPair(type.getAlgorithm(), keyPair, new Date());
|
||||
|
||||
PGPKeyPair pgpKeyPair;
|
||||
try {
|
||||
pgpKeyPair = ImplementationFactory.getInstance().getPGPKeyPair(type.getAlgorithm(), keyPair, new Date());
|
||||
} catch (PGPException e) {
|
||||
// When generating EdDSA keys, the private key has an encoding length of 33 instead of 34, which results
|
||||
// in an exception. Therefore we just try again as a workaround.
|
||||
LOGGER.log(Level.INFO, "Private key has wrong length. Try again.", e);
|
||||
pgpKeyPair = generateKeyPair(spec);
|
||||
}
|
||||
return pgpKeyPair;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue