Package org.pgpainless.key.protection
Class PassphraseMapKeyRingProtector
- java.lang.Object
-
- org.pgpainless.key.protection.PassphraseMapKeyRingProtector
-
- All Implemented Interfaces:
SecretKeyPassphraseProvider,SecretKeyRingProtector
public class PassphraseMapKeyRingProtector extends java.lang.Object implements SecretKeyRingProtector, SecretKeyPassphraseProvider
Implementation of theSecretKeyRingProtectorwhich holds a map of key ids and their passwords. In case the needed passphrase is not contained in the map, themissingPassphraseCallbackwill be consulted, and the passphrase is added to the map.
-
-
Constructor Summary
Constructors Constructor Description PassphraseMapKeyRingProtector(java.util.Map<java.lang.Long,Passphrase> passphrases, KeyRingProtectionSettings protectionSettings, SecretKeyPassphraseProvider missingPassphraseCallback)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPassphrase(java.lang.Long keyId, Passphrase passphrase)Add a passphrase to the cache.voidforgetPassphrase(java.lang.Long keyId)Remove a passphrase from the cache.org.bouncycastle.openpgp.operator.PBESecretKeyDecryptorgetDecryptor(java.lang.Long keyId)Return a decryptor for the key of idkeyId.org.bouncycastle.openpgp.operator.PBESecretKeyEncryptorgetEncryptor(java.lang.Long keyId)Return an encryptor for the key of idkeyId.PassphrasegetPassphraseFor(java.lang.Long keyId)Return a passphrase for the given key.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider
getPassphraseFor
-
-
-
-
Constructor Detail
-
PassphraseMapKeyRingProtector
public PassphraseMapKeyRingProtector(@Nonnull java.util.Map<java.lang.Long,Passphrase> passphrases, @Nonnull KeyRingProtectionSettings protectionSettings, @Nullable SecretKeyPassphraseProvider missingPassphraseCallback)
-
-
Method Detail
-
addPassphrase
public void addPassphrase(@Nonnull java.lang.Long keyId, @Nullable Passphrase passphrase)Add a passphrase to the cache.- Parameters:
keyId- id of the keypassphrase- passphrase
-
forgetPassphrase
public void forgetPassphrase(@Nonnull java.lang.Long keyId)Remove a passphrase from the cache. The passphrase will be cleared and then removed.- Parameters:
keyId- id of the key
-
getPassphraseFor
@Nullable public Passphrase getPassphraseFor(java.lang.Long keyId)
Description copied from interface:SecretKeyPassphraseProviderReturn a passphrase for the given key. If no record has been found, return null. Note: In case of an unprotected secret key, this method must may not return null, but aPassphrasewith a content of null.- Specified by:
getPassphraseForin interfaceSecretKeyPassphraseProvider- Parameters:
keyId- if of the secret key- Returns:
- passphrase or null, if no passphrase record has been found.
-
getDecryptor
@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor getDecryptor(@Nonnull java.lang.Long keyId) throws org.bouncycastle.openpgp.PGPExceptionDescription copied from interface:SecretKeyRingProtectorReturn a decryptor for the key of idkeyId. This method returns null if the key is unprotected.- Specified by:
getDecryptorin interfaceSecretKeyRingProtector- Parameters:
keyId- id of the key- Returns:
- decryptor for the key
- Throws:
org.bouncycastle.openpgp.PGPException
-
getEncryptor
@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor getEncryptor(@Nonnull java.lang.Long keyId) throws org.bouncycastle.openpgp.PGPExceptionDescription copied from interface:SecretKeyRingProtectorReturn an encryptor for the key of idkeyId. This method returns null if the key is unprotected.- Specified by:
getEncryptorin interfaceSecretKeyRingProtector- Parameters:
keyId- id of the key- Returns:
- encryptor for the key
- Throws:
org.bouncycastle.openpgp.PGPException- if the encryptor cannot be created for some reason
-
-