Package org.pgpainless.key.protection
Class CachingSecretKeyRingProtector
- java.lang.Object
-
- org.pgpainless.key.protection.CachingSecretKeyRingProtector
-
- All Implemented Interfaces:
SecretKeyPassphraseProvider
,SecretKeyRingProtector
public class CachingSecretKeyRingProtector extends java.lang.Object implements SecretKeyRingProtector, SecretKeyPassphraseProvider
Implementation of theSecretKeyRingProtector
which holds a map of key ids and their passwords. In case the needed passphrase is not contained in the map, themissingPassphraseCallback
will be consulted, and the passphrase is added to the map.
-
-
Constructor Summary
Constructors Constructor Description CachingSecretKeyRingProtector()
CachingSecretKeyRingProtector(java.util.Map<java.lang.Long,Passphrase> passphrases, KeyRingProtectionSettings protectionSettings, SecretKeyPassphraseProvider missingPassphraseCallback)
CachingSecretKeyRingProtector(SecretKeyPassphraseProvider missingPassphraseCallback)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPassphrase(java.lang.Long keyId, Passphrase passphrase)
Add a passphrase to the cache.void
addPassphrase(org.bouncycastle.openpgp.PGPKeyRing keyRing, Passphrase passphrase)
Remember the given passphrase for all keys in the given key ring.void
addPassphrase(org.bouncycastle.openpgp.PGPPublicKey key, Passphrase passphrase)
Remember the given passphrase for the given (sub-)key.void
addPassphrase(OpenPgpFingerprint fingerprint, Passphrase passphrase)
void
forgetPassphrase(java.lang.Long keyId)
Remove a passphrase from the cache.void
forgetPassphrase(org.bouncycastle.openpgp.PGPKeyRing keyRing)
Forget the passphrase to all keys in the provided key ring.void
forgetPassphrase(org.bouncycastle.openpgp.PGPPublicKey key)
Forget the passphrase of the given public key.org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor
getDecryptor(java.lang.Long keyId)
Return a decryptor for the key of idkeyId
.org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor
getEncryptor(java.lang.Long keyId)
Return an encryptor for the key of idkeyId
.Passphrase
getPassphraseFor(java.lang.Long keyId)
Return a passphrase for the given key.boolean
hasPassphrase(java.lang.Long keyId)
boolean
hasPassphraseFor(java.lang.Long keyId)
-
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
-
CachingSecretKeyRingProtector
public CachingSecretKeyRingProtector()
-
CachingSecretKeyRingProtector
public CachingSecretKeyRingProtector(@Nullable SecretKeyPassphraseProvider missingPassphraseCallback)
-
CachingSecretKeyRingProtector
public CachingSecretKeyRingProtector(@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, @Nonnull Passphrase passphrase)
Add a passphrase to the cache.- Parameters:
keyId
- id of the keypassphrase
- passphrase
-
addPassphrase
public void addPassphrase(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing, @Nonnull Passphrase passphrase)
Remember the given passphrase for all keys in the given key ring.- Parameters:
keyRing
- key ringpassphrase
- passphrase
-
addPassphrase
public void addPassphrase(@Nonnull org.bouncycastle.openpgp.PGPPublicKey key, @Nonnull Passphrase passphrase)
Remember the given passphrase for the given (sub-)key.- Parameters:
key
- keypassphrase
- passphrase
-
addPassphrase
public void addPassphrase(@Nonnull OpenPgpFingerprint fingerprint, @Nonnull Passphrase 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
-
forgetPassphrase
public void forgetPassphrase(@Nonnull org.bouncycastle.openpgp.PGPKeyRing keyRing)
Forget the passphrase to all keys in the provided key ring.- Parameters:
keyRing
- key ring
-
forgetPassphrase
public void forgetPassphrase(@Nonnull org.bouncycastle.openpgp.PGPPublicKey key)
Forget the passphrase of the given public key.- Parameters:
key
- key
-
getPassphraseFor
@Nullable public Passphrase getPassphraseFor(java.lang.Long keyId)
Description copied from interface:SecretKeyPassphraseProvider
Return 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 aPassphrase
with a content of null.- Specified by:
getPassphraseFor
in interfaceSecretKeyPassphraseProvider
- Parameters:
keyId
- if of the secret key- Returns:
- passphrase or null, if no passphrase record has been found.
-
hasPassphrase
public boolean hasPassphrase(java.lang.Long keyId)
- Specified by:
hasPassphrase
in interfaceSecretKeyPassphraseProvider
-
hasPassphraseFor
public boolean hasPassphraseFor(java.lang.Long keyId)
- Specified by:
hasPassphraseFor
in interfaceSecretKeyRingProtector
-
getDecryptor
@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor getDecryptor(@Nonnull java.lang.Long keyId) throws org.bouncycastle.openpgp.PGPException
Description copied from interface:SecretKeyRingProtector
Return a decryptor for the key of idkeyId
. This method returns null if the key is unprotected.- Specified by:
getDecryptor
in 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.PGPException
Description copied from interface:SecretKeyRingProtector
Return an encryptor for the key of idkeyId
. This method returns null if the key is unprotected.- Specified by:
getEncryptor
in 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
-
-