Class PGPEncryptService

java.lang.Object
com.adaptris.core.ServiceImp
com.adaptris.security.pgp.PGPEncryptService
All Implemented Interfaces:
AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, ConfigComment, 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 Details

    • PGPEncryptService

      public PGPEncryptService()
  • Method Details

    • doService

      public void doService(AdaptrisMessage message) throws ServiceException
      .
      Throws:
      ServiceException
    • 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(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 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(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 Boolean getIntegrityCheck()
      Get whether there should be integrity checks within the cipher text.
      Returns:
      Whether there should be integrity checks in the cipher text.
    • initService

      protected void initService()
      .
      Specified by:
      initService in class ServiceImp
    • closeService

      protected void closeService()
      .
      Specified by:
      closeService in class ServiceImp
    • prepare

      public void prepare()
      .
    • extractStream

      protected InputStream extractStream(AdaptrisMessage message, DataInputParameter<?> parameter, String warning) throws Exception
      Throws:
      Exception
    • extractString

      protected String extractString(AdaptrisMessage message, DataInputParameter<?> parameter, String warning) throws Exception
      Throws:
      Exception
    • insertStream

      protected <T> void insertStream(AdaptrisMessage message, DataOutputParameter<T> parameter, ByteArrayOutputStream value) throws Exception
      Throws:
      Exception
    • getDecoderStream

      protected static InputStream getDecoderStream(InputStream in) throws 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:
      IOException - if an error occurs reading the stream, or initialising the ArmoredInputStream.
    • processLine

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

      protected static void processLine(org.bouncycastle.openpgp.PGPSignature sig, byte[] line) throws SignatureException, IOException
      Throws:
      SignatureException
      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(ByteArrayOutputStream bOut, InputStream fIn) throws IOException
      Throws:
      IOException
    • readInputLine

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