Package org.pgpainless.key.protection
Class PasswordBasedSecretKeyRingProtector
- java.lang.Object
-
- org.pgpainless.key.protection.PasswordBasedSecretKeyRingProtector
-
- All Implemented Interfaces:
SecretKeyRingProtector
public class PasswordBasedSecretKeyRingProtector extends java.lang.Object implements SecretKeyRingProtector
ProvidesPBESecretKeyDecryptor
andPBESecretKeyEncryptor
objects while getting the passphrases from aSecretKeyPassphraseProvider
and using settings from anKeyRingProtectionSettings
.
-
-
Field Summary
Fields Modifier and Type Field Description protected SecretKeyPassphraseProvider
passphraseProvider
protected KeyRingProtectionSettings
protectionSettings
-
Constructor Summary
Constructors Constructor Description PasswordBasedSecretKeyRingProtector(KeyRingProtectionSettings settings, SecretKeyPassphraseProvider passphraseProvider)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PasswordBasedSecretKeyRingProtector
forKey(org.bouncycastle.openpgp.PGPKeyRing keyRing, Passphrase passphrase)
static PasswordBasedSecretKeyRingProtector
forKey(org.bouncycastle.openpgp.PGPSecretKey key, Passphrase passphrase)
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
.
-
-
-
Field Detail
-
protectionSettings
protected final KeyRingProtectionSettings protectionSettings
-
passphraseProvider
protected final SecretKeyPassphraseProvider passphraseProvider
-
-
Constructor Detail
-
PasswordBasedSecretKeyRingProtector
public PasswordBasedSecretKeyRingProtector(@Nonnull KeyRingProtectionSettings settings, @Nonnull SecretKeyPassphraseProvider passphraseProvider)
Constructor. Passphrases for keys are sourced from thepassphraseProvider
and decryptors/encryptors are constructed following the settings given insettings
.- Parameters:
settings
- S2K settings etc.passphraseProvider
- provider which provides passphrases.
-
-
Method Detail
-
forKey
public static PasswordBasedSecretKeyRingProtector forKey(org.bouncycastle.openpgp.PGPKeyRing keyRing, Passphrase passphrase)
-
forKey
public static PasswordBasedSecretKeyRingProtector forKey(org.bouncycastle.openpgp.PGPSecretKey key, Passphrase passphrase)
-
getDecryptor
@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor getDecryptor(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(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
-
-