Package org.c02e.jpgpj.key
Class KeyForSigning
java.lang.Object
org.c02e.jpgpj.Key
org.c02e.jpgpj.key.KeyForSigning
- All Implemented Interfaces:
Cloneable
Key that should be used exclusively for signing.
Regardless of PGP usage flags associated with the original key source,
only the last subkey flagged for signing will be used, and the key will be
used for nothing else (so the Encryptor
will use this key only for
signing, and not for encryption; and the Decryptor
will ignore this
key entirely). If no subkeys have been flagged for signing, this class
will automatically flag the subkey most likely to have been intended to be
used for signing.
Use like the following:
new Encryptor(
new KeyForSigning(new File("path/to/my/keys/alice-sec.gpg"), "password123"),
new KeyForEncryption(new File("path/to/my/keys/bob-pub.gpg"))
).encrypt(
new File("path/to/plaintext.txt"),
new File("path/to/ciphertext.txt.gpg")
);
- See Also:
-
Field Summary
Fields inherited from class org.c02e.jpgpj.Key
NO_PASSPHRASE, signingUid, subkeys
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty key.KeyForSigning
(File file) Loads first key from the specified file.KeyForSigning
(File file, char[] passphraseChars) Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(File file, String passphrase) Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(InputStream stream) Loads first key from the specified input stream.KeyForSigning
(InputStream stream, char[] passphraseChars) Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(InputStream stream, String passphrase) Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(String armor) Loads first key from the specified armored text.KeyForSigning
(String armor, char[] passphraseChars) Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(String armor, String passphrase) Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase.KeyForSigning
(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
-
KeyForSigning
public KeyForSigning()Constructs a new empty key. -
KeyForSigning
Constructs a new key with the specified subkeys. -
KeyForSigning
Loads first key from the specified armored text.- Throws:
org.bouncycastle.openpgp.PGPException
- if the text contains no keys.IOException
-
KeyForSigning
public KeyForSigning(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
-
KeyForSigning
public KeyForSigning(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. PreferKeyForSigning(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
-
KeyForSigning
Loads first key from the specified file.- Throws:
org.bouncycastle.openpgp.PGPException
- if the file contains no keys.IOException
-
KeyForSigning
public KeyForSigning(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
-
KeyForSigning
public KeyForSigning(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. PreferKeyForSigning(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
-
KeyForSigning
Loads first key from the specified input stream.- Throws:
org.bouncycastle.openpgp.PGPException
- if the input streame contains no keys.IOException
-
KeyForSigning
public KeyForSigning(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
-
KeyForSigning
public KeyForSigning(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. PreferKeyForSigning(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()
-