public class PassphraseMapKeyRingProtector extends Object implements SecretKeyRingProtector, SecretKeyPassphraseProvider
SecretKeyRingProtector
which holds a map of key ids and their passwords.
In case the needed passphrase is not contained in the map, the missingPassphraseCallback
will be consulted,
and the passphrase is added to the map.Constructor and Description |
---|
PassphraseMapKeyRingProtector(Map<Long,Passphrase> passphrases,
KeyRingProtectionSettings protectionSettings,
SecretKeyPassphraseProvider missingPassphraseCallback) |
Modifier and Type | Method and Description |
---|---|
void |
addPassphrase(Long keyId,
Passphrase passphrase)
Add a passphrase to the cache.
|
void |
forgetPassphrase(Long keyId)
Remove a passphrase from the cache.
|
org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor |
getDecryptor(Long keyId)
Return a decryptor for the key of id
keyId . |
org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor |
getEncryptor(Long keyId)
Return an encryptor for the key of id
keyId . |
Passphrase |
getPassphraseFor(Long keyId)
Return a passphrase for the given key.
|
public PassphraseMapKeyRingProtector(@Nonnull Map<Long,Passphrase> passphrases, @Nonnull KeyRingProtectionSettings protectionSettings, @Nullable SecretKeyPassphraseProvider missingPassphraseCallback)
public void addPassphrase(@Nonnull Long keyId, @Nullable Passphrase passphrase)
keyId
- id of the keypassphrase
- passphrasepublic void forgetPassphrase(@Nonnull Long keyId)
keyId
- id of the key@Nullable public Passphrase getPassphraseFor(@Nonnull Long keyId)
SecretKeyPassphraseProvider
Passphrase
with
a content of null.getPassphraseFor
in interface SecretKeyPassphraseProvider
keyId
- id of the key@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor getDecryptor(@Nonnull Long keyId)
SecretKeyRingProtector
keyId
.
This method returns null if the key is unprotected.getDecryptor
in interface SecretKeyRingProtector
keyId
- id of the key@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor getEncryptor(@Nonnull Long keyId) throws org.bouncycastle.openpgp.PGPException
SecretKeyRingProtector
keyId
.
This method returns null if the key is unprotected.getEncryptor
in interface SecretKeyRingProtector
keyId
- id of the keyorg.bouncycastle.openpgp.PGPException
- if the encryptor cannot be created for some reason