public class CryptoDataFormat
extends org.apache.camel.support.ServiceSupport
implements org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName
CryptoDataFormat
uses a specified key and algorithm to encrypt,
decrypt and verify exchange payloads. The Data format allows an
initialization vector to be supplied. The use of this initialization vector
or IV is different depending on the algorithm type block or streaming, but it
is desirable to be able to control it. Also in certain cases it may be
necessary to have access to the IV in the decryption phase and as the IV
doens't necessarily need to be kept secret it is ok to inline this in the
stream and read it out on the other side prior to decryption. For more
information on Initialization vectors see
CryptoDataFormat
can also calculate a Message Authentication Code for
the encrypted exchange contents based on a configurable MAC algorithm. The
calculated HMAC is appended to the stream after encryption. It is separated
from the stream in the decryption phase. The MAC is recalculated and verified
against the transmitted version to insure nothing was tampered with in
transit.For more information on Message Authentication Codes see
Constructor and Description |
---|
CryptoDataFormat() |
CryptoDataFormat(String algorithm,
Key key) |
CryptoDataFormat(String algorithm,
Key key,
String cryptoProvider) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart() |
protected void |
doStop() |
String |
getDataFormatName() |
void |
marshal(org.apache.camel.Exchange exchange,
Object graph,
OutputStream outputStream) |
void |
setAlgorithm(String algorithm)
Sets the JCE name of the Encryption Algorithm that should be used
|
void |
setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec)
Sets a custom
AlgorithmParameterSpec that should be used to
configure the Cipher. |
void |
setBufferSize(int bufferSize)
Set the size of the buffer used to
|
void |
setCryptoProvider(String cryptoProvider)
Sets the name of the JCE provider e.g.
|
void |
setInitializationVector(byte[] initializationVector) |
void |
setKey(Key key)
Set the key that should be used to encrypt or decrypt incoming encrypted exchanges.
|
void |
setMacAlgorithm(String macAlgorithm)
Sets the algorithm used to create the Hash-based Message Authentication
Code (HMAC) appended to the stream.
|
void |
setShouldAppendHMAC(boolean shouldAppendHMAC)
Whether a Hash-based Message Authentication Code (HMAC) should be
calculated and appended to the stream.
|
void |
setShouldInlineInitializationVector(boolean inline)
Meant for use with a Symmetric block Cipher and specifies that the
initialization vector should be written to the cipher stream ahead of the
encrypted ciphertext.
|
Object |
unmarshal(org.apache.camel.Exchange exchange,
InputStream encryptedStream) |
public static final String KEY
public String getDataFormatName()
getDataFormatName
in interface org.apache.camel.spi.DataFormatName
public void marshal(org.apache.camel.Exchange exchange, Object graph, OutputStream outputStream) throws Exception
marshal
in interface org.apache.camel.spi.DataFormat
Exception
public Object unmarshal(org.apache.camel.Exchange exchange, InputStream encryptedStream) throws Exception
unmarshal
in interface org.apache.camel.spi.DataFormat
Exception
protected void doStart() throws Exception
doStart
in class org.apache.camel.support.ServiceSupport
Exception
protected void doStop() throws Exception
doStop
in class org.apache.camel.support.ServiceSupport
Exception
public void setInitializationVector(byte[] initializationVector)
public void setShouldInlineInitializationVector(boolean inline)
inline
- true if the initialization vector should be inlined in the stream.public void setAlgorithm(String algorithm)
public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec)
AlgorithmParameterSpec
that should be used to
configure the Cipher. Note that if an Initalization vector is provided
then the IvParameterSpec will be used and any value set here will be
ignoredpublic void setCryptoProvider(String cryptoProvider)
public void setMacAlgorithm(String macAlgorithm)
public void setShouldAppendHMAC(boolean shouldAppendHMAC)
public void setKey(Key key)
public void setBufferSize(int bufferSize)
Apache Camel