Package org.c02e.jpgpj.key
Class KeyForEncryption
- java.lang.Object
-
- org.c02e.jpgpj.Key
-
- org.c02e.jpgpj.key.KeyForEncryption
-
- All Implemented Interfaces:
java.lang.Cloneable
public class KeyForEncryption extends Key
Key that should be used exclusively for encryption.Regardless of PGP usage flags associated with the original key source, only the last subkey flagged for encryption will be used, and the key will be used for nothing else (so the
Encryptor
will use this key only for encryption, and not for signing; and theDecryptor
will ignore this key entirely). If no subkeys have been flagged for encryption, this class will automatically flag the subkey most likely to have been intended to be used for encryption.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:
Key
-
-
Field Summary
-
Fields inherited from class org.c02e.jpgpj.Key
NO_PASSPHRASE, signingUid, subkeys
-
-
Constructor Summary
Constructors Constructor Description KeyForEncryption()
Constructs a new empty key.KeyForEncryption(java.io.File file)
Loads first key from the specified file.KeyForEncryption(java.io.InputStream stream)
Loads first key from the specified input stream.KeyForEncryption(java.lang.String armor)
Loads first key from the specified armored text.KeyForEncryption(java.util.List<Subkey> subkeys)
Constructs a new key with the specified subkeys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
setSubkeys(java.util.List<Subkey> x)
All subkeys, or an empty list.protected void
setSubkeysUsage()
-
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 Detail
-
KeyForEncryption
public KeyForEncryption()
Constructs a new empty key.
-
KeyForEncryption
public KeyForEncryption(java.util.List<Subkey> subkeys)
Constructs a new key with the specified subkeys.
-
KeyForEncryption
public KeyForEncryption(java.lang.String armor) throws java.io.IOException, org.bouncycastle.openpgp.PGPException
Loads first key from the specified armored text.- Throws:
org.bouncycastle.openpgp.PGPException
- if the text contains no keys.java.io.IOException
-
KeyForEncryption
public KeyForEncryption(java.io.File file) throws java.io.IOException, org.bouncycastle.openpgp.PGPException
Loads first key from the specified file.- Throws:
org.bouncycastle.openpgp.PGPException
- if the file contains no keys.java.io.IOException
-
KeyForEncryption
public KeyForEncryption(java.io.InputStream stream) throws java.io.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.java.io.IOException
-
-
Method Detail
-
setSubkeys
protected void setSubkeys(java.util.List<Subkey> x)
Description copied from class:Key
All subkeys, or an empty list.- Overrides:
setSubkeys
in classKey
-
setSubkeysUsage
protected void setSubkeysUsage()
-
-