mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-10 06:11:08 +01:00
Fix creating keys with Passphrase.emptyPassphrase()
Previously the code supplied `null` to BouncyCastle's encryptor/decryptor builder's build method and that caused NullPointerException to be thrown. The fix checks if the passphrase is empty and omits the BouncyCastle builder in that case. Fixes #16.
This commit is contained in:
parent
2c2acb996a
commit
59fe53c594
3 changed files with 58 additions and 2 deletions
|
|
@ -338,7 +338,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
|||
}
|
||||
|
||||
private PBESecretKeyEncryptor buildSecretKeyEncryptor() {
|
||||
PBESecretKeyEncryptor encryptor = passphrase == null ?
|
||||
PBESecretKeyEncryptor encryptor = passphrase == null || passphrase.isEmpty() ?
|
||||
null : // unencrypted key pair, otherwise AES-256 encrypted
|
||||
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, digestCalculator)
|
||||
.setProvider(ProviderFactory.getProvider())
|
||||
|
|
@ -347,7 +347,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
|||
}
|
||||
|
||||
private PBESecretKeyDecryptor buildSecretKeyDecryptor() throws PGPException {
|
||||
PBESecretKeyDecryptor decryptor = passphrase == null ?
|
||||
PBESecretKeyDecryptor decryptor = passphrase == null || passphrase.isEmpty() ?
|
||||
null :
|
||||
new JcePBESecretKeyDecryptorBuilder()
|
||||
.build(passphrase.getChars());
|
||||
|
|
|
|||
|
|
@ -91,6 +91,17 @@ public class Passphrase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the passphrase represents no password.
|
||||
*
|
||||
* @return empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
synchronized (lock) {
|
||||
return chars == null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a {@link Passphrase} instance that represents no password.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue