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
,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.
-
Field Summary
Fields inherited from class com.adaptris.core.ServiceImp
log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
.void
doService
(AdaptrisMessage message) .protected InputStream
extractStream
(AdaptrisMessage message, DataInputParameter<?> parameter, String warning) protected String
extractString
(AdaptrisMessage message, DataInputParameter<?> parameter, String warning) Get whether the cipher text output should be ASCII armor encoded.Get the encrypted cipher text.Get the clear text to encrypt.protected static InputStream
Obtains a stream that can be used to read PGP data from the provided stream.Get whether there should be integrity checks within the cipher text.protected static int
getLengthWithoutSeparatorOrTrailingWhitespace
(byte[] line) protected static int
getLengthWithoutWhiteSpace
(byte[] line) protected static byte[]
Get the pubilc key for encryption.protected void
.protected <T> void
insertStream
(AdaptrisMessage message, DataOutputParameter<T> parameter, ByteArrayOutputStream value) void
prepare()
.protected static void
processLine
(OutputStream aOut, org.bouncycastle.openpgp.PGPSignatureGenerator sGen, byte[] line) protected static void
processLine
(org.bouncycastle.openpgp.PGPSignature sig, byte[] line) protected static int
readInputLine
(ByteArrayOutputStream bOut, int lookAhead, InputStream fIn) protected static int
readInputLine
(ByteArrayOutputStream bOut, InputStream fIn) void
setArmorEncoding
(Boolean armorEncoding) Set whether the cipher text output should be ASCII armor encoded.void
setCipherText
(DataOutputParameter<?> cipherText) Set the encrypted cipher text.void
setClearText
(DataInputParameter<?> clearText) Set the clear text to encrypt.void
setIntegrityCheck
(Boolean integrityCheck) Set whether there should be integrity checks within the cipher text.void
setPublicKey
(DataInputParameter<?> publicKey) Set the public key for encryption.Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, enabled, getComments, getContinueOnFail, getEnabled, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setComments, setContinueOnFail, setEnabled, setIsTrackingEndpoint, setUniqueId, start, stop
-
Constructor Details
-
PGPEncryptService
public PGPEncryptService()
-
-
Method Details
-
doService
.- Throws:
ServiceException
-
setPublicKey
Set the public key for encryption.- Parameters:
publicKey
- The public key.
-
getPublicKey
Get the pubilc key for encryption.- Returns:
- The public key.
-
setClearText
Set the clear text to encrypt.- Parameters:
clearText
- The clear text.
-
getClearText
Get the clear text to encrypt.- Returns:
- The clear text.
-
setCipherText
Set the encrypted cipher text.- Parameters:
cipherText
- The cipher text.
-
getCipherText
Get the encrypted cipher text.- Returns:
- The cipher text.
-
setArmorEncoding
Set whether the cipher text output should be ASCII armor encoded.- Parameters:
armorEncoding
- Whether the cipher text should be armor encoded.
-
getArmorEncoding
Get whether the cipher text output should be ASCII armor encoded.- Returns:
- Whether the cipher text should be armor encoded.
-
setIntegrityCheck
Set whether there should be integrity checks within the cipher text.- Parameters:
integrityCheck
- Whether there should be integrity checks in the cipher text.
-
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 classServiceImp
-
closeService
protected void closeService().- Specified by:
closeService
in classServiceImp
-
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
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 theArmoredInputStream
.
-
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
- Throws:
IOException
-
readInputLine
protected static int readInputLine(ByteArrayOutputStream bOut, int lookAhead, InputStream fIn) throws IOException - Throws:
IOException
-