Package org.pgpainless.key.protection

# Class BaseSecretKeyRingProtector

java.lang.Object
org.pgpainless.key.protection.BaseSecretKeyRingProtector

All Implemented Interfaces:
  `SecretKeyRingProtector`

Direct Known Subclasses:
  `PasswordBasedSecretKeyRingProtector`

public class BaseSecretKeyRingProtector extends Object implements SecretKeyRingProtector
Basic `SecretKeyRingProtector` implementation that respects the users `KeyRingProtectionSettings` when encrypting keys.

## Constructor Summary

Constructors
Constructor
Description
`BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider)`
Constructor that uses the given `SecretKeyPassphraseProvider` to retrieve passphrases and PGPainless' default `KeyRingProtectionSettings`.
`BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider, KeyRingProtectionSettings protectionSettings)`
Constructor that uses the given `SecretKeyPassphraseProvider` and `KeyRingProtectionSettings`.

## Method Summary

Modifier and Type
Method
Description
`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`.
`boolean`
`hasPassphraseFor(Long keyId)`
Returns true, if the protector has a passphrase for the key with the given key-id.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### BaseSecretKeyRingProtector

public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider)
Constructor that uses the given `SecretKeyPassphraseProvider` to retrieve passphrases and PGPainless' default `KeyRingProtectionSettings`.

Parameters:
  `passphraseProvider` - provider for passphrases

### BaseSecretKeyRingProtector

public BaseSecretKeyRingProtector(SecretKeyPassphraseProvider passphraseProvider, KeyRingProtectionSettings protectionSettings)
Constructor that uses the given `SecretKeyPassphraseProvider` and `KeyRingProtectionSettings`.

Parameters:
  `passphraseProvider` - provider for passphrases
  `protectionSettings` - protection settings

## Method Details

### hasPassphraseFor

public boolean hasPassphraseFor(Long keyId)
Description copied from interface: `SecretKeyRingProtector`
Returns true, if the protector has a passphrase for the key with the given key-id.

Specified by:
  `hasPassphraseFor` in interface `SecretKeyRingProtector`
Parameters:
  `keyId` - key id
Returns:
  true if it has a passphrase, false otherwise

### getDecryptor

@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor getDecryptor(Long keyId) throws org.bouncycastle.openpgp.PGPException
Description copied from interface: `SecretKeyRingProtector`
Return a decryptor for the key of id `keyId`. This method returns null if the key is unprotected.

Specified by:
  `getDecryptor` in interface `SecretKeyRingProtector`
Parameters:
  `keyId` - id of the key
Returns:
  decryptor for the key
Throws:
  `org.bouncycastle.openpgp.PGPException` - if the decryptor cannot be created for some reason

### getEncryptor

@Nullable public org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor getEncryptor(Long keyId) throws org.bouncycastle.openpgp.PGPException
Description copied from interface: `SecretKeyRingProtector`
Return an encryptor for the key of id `keyId`. This method returns null if the key is unprotected.

Specified by:
  `getEncryptor` in interface `SecretKeyRingProtector`
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