Package com.adaptris.security.pgp
Class PGPEncryptService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.security.pgp.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 ServiceImpThis 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 Summary
Constructors Constructor Description PGPEncryptService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseService().voiddoService(AdaptrisMessage message).protected java.io.InputStreamextractStream(AdaptrisMessage message, DataInputParameter parameter, java.lang.String warning)protected java.lang.StringextractString(AdaptrisMessage message, DataInputParameter parameter, java.lang.String warning)java.lang.BooleangetArmorEncoding()Get whether the cipher text output should be ASCII armor encoded.DataOutputParametergetCipherText()Get the encrypted cipher text.DataInputParametergetClearText()Get the clear text to encrypt.protected static java.io.InputStreamgetDecoderStream(java.io.InputStream in)Obtains a stream that can be used to read PGP data from the provided stream.java.lang.BooleangetIntegrityCheck()Get whether there should be integrity checks within the cipher text.protected static intgetLengthWithoutSeparatorOrTrailingWhitespace(byte[] line)protected static intgetLengthWithoutWhiteSpace(byte[] line)protected static byte[]getLineSeparator()DataInputParametergetPublicKey()Get the pubilc key for encryption.protected voidinitService().protected voidinsertStream(AdaptrisMessage message, DataOutputParameter parameter, java.io.ByteArrayOutputStream value)voidprepare().protected static voidprocessLine(java.io.OutputStream aOut, org.bouncycastle.openpgp.PGPSignatureGenerator sGen, byte[] line)protected static voidprocessLine(org.bouncycastle.openpgp.PGPSignature sig, byte[] line)protected static intreadInputLine(java.io.ByteArrayOutputStream bOut, int lookAhead, java.io.InputStream fIn)protected static intreadInputLine(java.io.ByteArrayOutputStream bOut, java.io.InputStream fIn)voidsetArmorEncoding(java.lang.Boolean armorEncoding)Set whether the cipher text output should be ASCII armor encoded.voidsetCipherText(DataOutputParameter cipherText)Set the encrypted cipher text.voidsetClearText(DataInputParameter clearText)Set the clear text to encrypt.voidsetIntegrityCheck(java.lang.Boolean integrityCheck)Set whether there should be integrity checks within the cipher text.voidsetPublicKey(DataInputParameter publicKey)Set the public key for encryption.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
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(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.
-
initService
protected void initService()
.- Specified by:
initServicein classServiceImp
-
closeService
protected void closeService()
.- Specified by:
closeServicein classServiceImp
-
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.IOExceptionObtains 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
ArmoredInputStreamis 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 theArmoredInputStream.
-
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.SignatureExceptionjava.io.IOException
-
processLine
protected static void processLine(org.bouncycastle.openpgp.PGPSignature sig, byte[] line) throws java.security.SignatureException, java.io.IOException- Throws:
java.security.SignatureExceptionjava.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
-
-