Class KeyForDecryption

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class KeyForDecryption
    extends Key
    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:
    Key
    • Constructor Detail

      • KeyForDecryption

        public KeyForDecryption()
        Constructs a new empty key.
      • KeyForDecryption

        public KeyForDecryption​(java.util.List<Subkey> subkeys)
        Constructs a new key with the specified subkeys.
      • KeyForDecryption

        public KeyForDecryption​(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
      • KeyForDecryption

        public KeyForDecryption​(java.lang.String armor,
                                char[] passphraseChars)
                         throws java.io.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.
        java.io.IOException
      • KeyForDecryption

        public KeyForDecryption​(java.lang.String armor,
                                java.lang.String passphrase)
                         throws java.io.IOException,
                                org.bouncycastle.openpgp.PGPException
        Loads first key from the specified armored text, and sets the passphrase of all subkeys to the specified passphrase. Prefer KeyForDecryption(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.
        java.io.IOException
      • KeyForDecryption

        public KeyForDecryption​(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
      • KeyForDecryption

        public KeyForDecryption​(java.io.File file,
                                char[] passphraseChars)
                         throws java.io.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.
        java.io.IOException
      • KeyForDecryption

        public KeyForDecryption​(java.io.File file,
                                java.lang.String passphrase)
                         throws java.io.IOException,
                                org.bouncycastle.openpgp.PGPException
        Loads first key from the specified file, and sets the passphrase of all subkeys to the specified passphrase. Prefer KeyForDecryption(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.
        java.io.IOException
      • KeyForDecryption

        public KeyForDecryption​(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
      • KeyForDecryption

        public KeyForDecryption​(java.io.InputStream stream,
                                char[] passphraseChars)
                         throws java.io.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.
        java.io.IOException
      • KeyForDecryption

        public KeyForDecryption​(java.io.InputStream stream,
                                java.lang.String passphrase)
                         throws java.io.IOException,
                                org.bouncycastle.openpgp.PGPException
        Loads first key from the specified input stream, and sets the passphrase of all subkeys to the specified passphrase. Prefer KeyForDecryption(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.
        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 class Key
      • setSubkeysUsage

        protected void setSubkeysUsage()