Package org.c02e.jpgpj.key
Class KeyForDecryption
java.lang.Object
org.c02e.jpgpj.Key
org.c02e.jpgpj.key.KeyForDecryption
- All Implemented Interfaces:
Cloneable
Key that should be used exclusively for decryption.
Regardless of PGP usage flags associated with the original key source,
all subkeys of this key will be flagged to be used for decryption and
nothing else (so the Decryptor
will try all subkeys of this key
when decrypting, but will ignore all subkeys when verifying;
and the Encryptor
will ignore this key entirely).
Use like the following:
new Decryptor(
new KeyForVerification(new File("path/to/my/keys/alice-pub.gpg")),
new KeyForDecryption(new File("path/to/my/keys/bob-sec.gpg"), "b0bru1z!")
).decrypt(
new File("path/to/ciphertext.txt.gpg"),
new File("path/back-to/plaintext.txt")
);
- See Also:
-
Field Summary
Fields inherited from class org.c02e.jpgpj.Key
NO_PASSPHRASE, signingUid, subkeys
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty key.KeyForDecryption
(File file) Loads first key from the specified file.KeyForDecryption
(File file, char[] passphraseChars) Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(File file, String passphrase) Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(InputStream stream) Loads first key from the specified input stream.KeyForDecryption
(InputStream stream, char[] passphraseChars) Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(InputStream stream, String passphrase) Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(String armor) Loads first key from the specified armored text.KeyForDecryption
(String armor, char[] passphraseChars) Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(String armor, String passphrase) Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase.KeyForDecryption
(List<Subkey> subkeys) Constructs a new key with the specified subkeys. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
setSubkeys
(List<Subkey> x) All subkeys, or an empty list.protected void
Methods inherited from class org.c02e.jpgpj.Key
clearSecrets, clone, findAll, findAll, findById, getDecryption, getEncryption, getMaster, getSigning, getSigningUid, getSubkeys, getUids, getVerification, isForDecryption, isForEncryption, isForSigning, isForVerification, load, load, load, matches, matches, newRing, setNoPassphrase, setPassphrase, setPassphraseChars, setSigningUid, toPublicKey, toString
-
Constructor Details
-
KeyForDecryption
public KeyForDecryption()Constructs a new empty key. -
KeyForDecryption
Constructs a new key with the specified subkeys. -
KeyForDecryption
Loads first key from the specified armored text.- Throws:
org.bouncycastle.openpgp.PGPException
- if the text contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(String armor, char[] passphraseChars) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase.- Throws:
org.bouncycastle.openpgp.PGPException
- if the text contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(String armor, String passphrase) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase. PreferKeyForDecryption(String, char[])
to avoid creating extra copies of the passphrase in memory that cannot be cleaned up.- Throws:
org.bouncycastle.openpgp.PGPException
- if the text contains no keys.IOException
-
KeyForDecryption
Loads first key from the specified file.- Throws:
org.bouncycastle.openpgp.PGPException
- if the file contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(File file, char[] passphraseChars) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase.- Throws:
org.bouncycastle.openpgp.PGPException
- if the file contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(File file, String passphrase) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase. PreferKeyForDecryption(File, char[])
to avoid creating extra copies of the passphrase in memory that cannot be cleaned up.- Throws:
org.bouncycastle.openpgp.PGPException
- if the file contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(InputStream stream) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified input stream.- Throws:
org.bouncycastle.openpgp.PGPException
- if the input streame contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(InputStream stream, char[] passphraseChars) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase.- Throws:
org.bouncycastle.openpgp.PGPException
- if the input streame contains no keys.IOException
-
KeyForDecryption
public KeyForDecryption(InputStream stream, String passphrase) throws IOException, org.bouncycastle.openpgp.PGPException Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase. PreferKeyForDecryption(InputStream, char[])
to avoid creating extra copies of the passphrase in memory that cannot be cleaned up.- Throws:
org.bouncycastle.openpgp.PGPException
- if the input streame contains no keys.IOException
-
-
Method Details
-
setSubkeys
Description copied from class:Key
All subkeys, or an empty list.- Overrides:
setSubkeys
in classKey
-
setSubkeysUsage
protected void setSubkeysUsage()
-