Class PGPEncryptService

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Encrypt data using a PGP/GPG public key",
                      tag="pgp,gpg,encrypt,public key",
                      since="3.9.2")
    public class PGPEncryptService
    extends ServiceImp
    This service provides a way to encrypt messages with GPG/PGP. It requires a public key or the intended recipient, and a message to encrypt. Optionally it will ASCII armor encode the cipher text (default), and include extra integrity checks (default).
    
        <pgp-encrypt>
            <unique-id>mad-lalande</unique-id>
            <public-key class="constant-data-input-parameter">
                <value>-----BEGIN PGP PUBLIC KEY BLOCK-----
    
        mQENBF2ckxABCAC5Kfu39ky3OIXkxwWOJx70G2dLRYvDMHXf3ZraUPNRMIhh3ZGx
        -----END PGP PUBLIC KEY BLOCK-----</value>
            </public-key>
            <clear-text class="stream-payload-input-parameter"/>             <!-- clear text comes from message payload -->
            <cipher-text class="stream-payload-output-parameter"/>           <!-- cipher text goes back into the message payload -->
            <armor-encoding>true</armor-encoding>
            <integrity-check>true</integrity-check>
        </pgp-encrypt>
     

    In the adapter configuration file this class is aliased as pgp-encrypt which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • PGPEncryptService

        public PGPEncryptService()
    • Method Detail

      • setPublicKey

        public void setPublicKey​(DataInputParameter publicKey)
        Set the public key for encryption.
        Parameters:
        publicKey - The public key.
      • getPublicKey

        public DataInputParameter getPublicKey()
        Get the pubilc key for encryption.
        Returns:
        The public key.
      • setClearText

        public void setClearText​(DataInputParameter clearText)
        Set the clear text to encrypt.
        Parameters:
        clearText - The clear text.
      • getClearText

        public DataInputParameter getClearText()
        Get the clear text to encrypt.
        Returns:
        The clear text.
      • setCipherText

        public void setCipherText​(DataOutputParameter cipherText)
        Set the encrypted cipher text.
        Parameters:
        cipherText - The cipher text.
      • getCipherText

        public DataOutputParameter getCipherText()
        Get the encrypted cipher text.
        Returns:
        The cipher text.
      • setArmorEncoding

        public void setArmorEncoding​(java.lang.Boolean armorEncoding)
        Set whether the cipher text output should be ASCII armor encoded.
        Parameters:
        armorEncoding - Whether the cipher text should be armor encoded.
      • getArmorEncoding

        public java.lang.Boolean getArmorEncoding()
        Get whether the cipher text output should be ASCII armor encoded.
        Returns:
        Whether the cipher text should be armor encoded.
      • setIntegrityCheck

        public void setIntegrityCheck​(java.lang.Boolean integrityCheck)
        Set whether there should be integrity checks within the cipher text.
        Parameters:
        integrityCheck - Whether there should be integrity checks in the cipher text.
      • getIntegrityCheck

        public java.lang.Boolean getIntegrityCheck()
        Get whether there should be integrity checks within the cipher text.
        Returns:
        Whether there should be integrity checks in the cipher text.
      • prepare

        public void prepare()
        .
      • extractStream

        protected java.io.InputStream extractStream​(AdaptrisMessage message,
                                                    DataInputParameter parameter,
                                                    java.lang.String warning)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • extractString

        protected java.lang.String extractString​(AdaptrisMessage message,
                                                 DataInputParameter parameter,
                                                 java.lang.String warning)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • insertStream

        protected void insertStream​(AdaptrisMessage message,
                                    DataOutputParameter parameter,
                                    java.io.ByteArrayOutputStream value)
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getDecoderStream

        protected static java.io.InputStream getDecoderStream​(java.io.InputStream in)
                                                       throws java.io.IOException
        Obtains a stream that can be used to read PGP data from the provided stream.

        If the initial bytes of the underlying stream are binary PGP encodings, then the stream will be returned directly, otherwise an ArmoredInputStream is used to wrap the provided stream and remove ASCII-Armored encoding.

        Parameters:
        in - the stream to be checked and possibly wrapped.
        Returns:
        a stream that will return PGP binary encoded data.
        Throws:
        java.io.IOException - if an error occurs reading the stream, or initialising the ArmoredInputStream.
      • processLine

        protected static void processLine​(java.io.OutputStream aOut,
                                          org.bouncycastle.openpgp.PGPSignatureGenerator sGen,
                                          byte[] line)
                                   throws java.security.SignatureException,
                                          java.io.IOException
        Throws:
        java.security.SignatureException
        java.io.IOException
      • processLine

        protected static void processLine​(org.bouncycastle.openpgp.PGPSignature sig,
                                          byte[] line)
                                   throws java.security.SignatureException,
                                          java.io.IOException
        Throws:
        java.security.SignatureException
        java.io.IOException
      • getLengthWithoutWhiteSpace

        protected static int getLengthWithoutWhiteSpace​(byte[] line)
      • getLengthWithoutSeparatorOrTrailingWhitespace

        protected static int getLengthWithoutSeparatorOrTrailingWhitespace​(byte[] line)
      • getLineSeparator

        protected static byte[] getLineSeparator()
      • readInputLine

        protected static int readInputLine​(java.io.ByteArrayOutputStream bOut,
                                           java.io.InputStream fIn)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readInputLine

        protected static int readInputLine​(java.io.ByteArrayOutputStream bOut,
                                           int lookAhead,
                                           java.io.InputStream fIn)
                                    throws java.io.IOException
        Throws:
        java.io.IOException