Package com.adaptris.security.pgp
Class PGPDecryptService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.security.pgp.PGPDecryptService
-
- All Implemented Interfaces:
AdaptrisComponent,ComponentLifecycle,ComponentLifecycleExtension,MessageEventGenerator,Service,StateManagedComponent
@ComponentProfile(summary="Decrypt data using a PGP/GPG private key", tag="pgp,gpg,decrypt,private key", since="3.9.2") public class PGPDecryptService extends ServiceImpThis service provides a way to decrypt GPG/PGP encrypted messages. It requires a private key, the passphrase to unlock the key, and an encrypted message.<pgp-decrypt> <unique-id>trusting-mayer</unique-id> <private-key class="constant-data-input-parameter"> <value>-----BEGIN PGP PRIVATE KEY BLOCK----- lQPGBF2ckxABCAC5Kfu39ky3OIXkxwWOJx70G2dLRYvDMHXf3ZraUPNRMIhh3ZGx -----END PGP PRIVATE KEY BLOCK-----</value> </private-key> <passphrase class="constant-data-input-parameter"> <value>my5ecr3tP455w0rd</value> </passphrase> <cipher-text class="stream-payload-input-parameter"/> <!-- cipher text comes from message payload --> <clear-text class="stream-payload-output-parameter"/> <!-- clear text goes back into the message payload --> </pgp-decrypt>In the adapter configuration file this class is aliased as pgp-decrypt which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Constructor Summary
Constructors Constructor Description PGPDecryptService()
-
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)DataInputParametergetCipherText()Get the cipher text to decrypt.DataOutputParametergetClearText()Get the decrypted clear text.protected static java.io.InputStreamgetDecoderStream(java.io.InputStream in)Obtains a stream that can be used to read PGP data from the provided stream.protected static intgetLengthWithoutSeparatorOrTrailingWhitespace(byte[] line)protected static intgetLengthWithoutWhiteSpace(byte[] line)protected static byte[]getLineSeparator()DataInputParametergetPassphrase()Get the passphrase to unlock the private key.DataInputParametergetPrivateKey()Get the private key for decryption.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)voidsetCipherText(DataInputParameter cipherText)Set the cipher text to decrypt.voidsetClearText(DataOutputParameter clearText)Set the decrypted clear text.voidsetPassphrase(DataInputParameter passphrase)Set the passphrase to unlock the private key.voidsetPrivateKey(DataInputParameter privateKey)Set the private key for decryption.-
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
-
setPrivateKey
public void setPrivateKey(DataInputParameter privateKey)
Set the private key for decryption.- Parameters:
privateKey- The private key.
-
getPrivateKey
public DataInputParameter getPrivateKey()
Get the private key for decryption.- Returns:
- The private key.
-
setCipherText
public void setCipherText(DataInputParameter cipherText)
Set the cipher text to decrypt.- Parameters:
cipherText- The cipher text.
-
getCipherText
public DataInputParameter getCipherText()
Get the cipher text to decrypt.- Returns:
- The cipher text.
-
setPassphrase
public void setPassphrase(DataInputParameter passphrase)
Set the passphrase to unlock the private key.- Parameters:
passphrase- The passphrase.
-
getPassphrase
public DataInputParameter getPassphrase()
Get the passphrase to unlock the private key.- Returns:
- The passphrase.
-
setClearText
public void setClearText(DataOutputParameter clearText)
Set the decrypted clear text.- Parameters:
clearText- The clear text.
-
getClearText
public DataOutputParameter getClearText()
Get the decrypted clear text.- Returns:
- The clear 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
-
-