camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Crypto
Date Wed, 30 Jan 2013 15:36:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Crypto">Crypto</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~sdanig">Daniel
Gredler</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Doc updates for CAMEL-6019 (Add PGP signature and signature verification support to
PGPDataFormat)<br />
    </div>
        <br/>
                         <h4>Changes (10)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Name || Type || Default || Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{keyUserid}} | {{String}} |
{{null}} | The userid of the key in the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">pgp
keyring</span> <span class="diff-added-words"style="background-color: #dfd;">PGP
keyring.</span> | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{password}} | {{String}} |
{{null}} | Password used when opening the private key (not used for <span class="diff-changed-words">encryption)<span
class="diff-added-chars"style="background-color: #dfd;">.</span></span> | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{keyFileName}} | {{String}}
| {{null}} | Filename of the <span class="diff-changed-words">keyring<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">,</span><span
class="diff-added-chars"style="background-color: #dfd;">;</span></span> must
be accessible as a classpath resource (but you can specify a location in the file system by
using the &quot;file:&quot; <span class="diff-changed-words">prefix)<span
class="diff-added-chars"style="background-color: #dfd;">.</span></span> | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{signatureKeyUserid}} | {{String}} | {{null}} | *Since Camel 2.11.0* Optional userid of the
key in the PGP keyring to use for signing (during encryption) or signature verification (during
decryption) .| <br>| {{signaturePassword}} | {{String}} | {{null}} | *Since Camel 2.11.0*
Optional password used when opening the private key used for signing (during encryption).
| <br>| {{signatureKeyFileName}} | {{String}} | {{null}} | *Since Camel 2.11.0* Optional
filename of the keyring to use for signing (during encryption) or for signature verification
(during decryption); must be accessible as a classpath resource (but you can specify a location
in the file system by using the &quot;file:&quot; prefix). | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{armored}} | {{boolean}} |
{{false}} | This option will cause <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">pgp</span>
<span class="diff-added-words"style="background-color: #dfd;">PGP</span> to base64
encode the encrypted text, making it available for copy/paste, etc. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{integrity}} | {{boolean}}
| {{true}} | <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">add
a</span> <span class="diff-added-words"style="background-color: #dfd;">Adds an</span>
integrity check/sign into the encryption <span class="diff-changed-words">file<span
class="diff-added-chars"style="background-color: #dfd;">.</span></span> | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{div:class=confluenceTableSmall} <br>||
Name || Type || Description || <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{CamelPGPDataFormatKeyFileName}}
| {{String}} | *Since Camel 2.11.0* Filename of the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">keyring,
Will</span> <span class="diff-added-words"style="background-color: #dfd;">keyring;
will</span> override existing setting directly on the PGPDataFormat. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{CamelPGPDataFormatKeyUserid}}
| {{String}} | *Since Camel 2.11.0* The userid of the key in the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">pgp
keyring, Will</span> <span class="diff-added-words"style="background-color: #dfd;">PGP
keyring; will</span> override existing setting directly on the PGPDataFormat. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{CamelPGPDataFormatKeyPassword}}
| {{String}} | *Since Camel 2.11.0* Password used when opening the private <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">key,
Will</span> <span class="diff-added-words"style="background-color: #dfd;">key;
will</span> override existing setting directly on the PGPDataFormat. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{CamelPGPDataFormatSignatureKeyFileName}} | {{String}} | *Since Camel 2.11.0* Filename of
the signature keyring; will override existing setting directly on the PGPDataFormat. | <br>|
{{CamelPGPDataFormatSignatureKeyUserid}} | {{String}} | *Since Camel 2.11.0* The userid of
the signature key in the PGP keyring; will override existing setting directly on the PGPDataFormat.
| <br>| {{CamelPGPDataFormatSignatureKeyPassword}} | {{String}} | *Since Camel 2.11.0*
Password used when opening the signature private key; will override existing setting directly
on the PGPDataFormat. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Encrypting with PGPDataFormat
<br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Crypto-Crypto"></a>Crypto</h2>
<p><b>Available as of Camel 2.3</b><br/>
<b>PGP Available as of Camel 2.9</b></p>

<p>The Crypto <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> integrates the Java Cryptographic Extension into Camel, allowing simple and
flexible encryption and decryption of messages using Camel's familiar marshall and unmarshal
formatting mechanism. It assumes marshalling to mean encryption to cyphertext and unmarshalling
to mean decryption back to the original plaintext.</p>

<h3><a name="Crypto-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>algorithm</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>DES/CBC/PKCS5Padding</tt> </td>
<td class='confluenceTd'> The JCE algoorithm name indicating the cryptographic algorithm
that will be used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>algorithmParamterSpec</tt> </td>
<td class='confluenceTd'> <tt>AlgorithmParameterSpec</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'>A JCE AlgorithmParameterSpec used to initialize the Cipher.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>bufferSize</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <tt>2048</tt> </td>
<td class='confluenceTd'> the size of the buffer used in the signature process. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>cryptoProvider</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The name of the JCE Security Provider that should be used.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>initializationVector</tt> </td>
<td class='confluenceTd'> <tt>byte[]</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> A byte array containing the Initialization Vector that will
be used to initialize the Cipher. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>inline</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Flag indicating that the configured IV should be inlined into
the encrypted data stream. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>macAlgorithm</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The JCE algorithm name indicating the Message Authentication
algorithm. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>shouldAppendHMAC</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Flag indicating that a Message Authentication Code should
be calculated and appended to the encrypted data.</td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Crypto-BasicUsage"></a>Basic Usage</h3>
<p>At its most basic all that is required to encrypt/decrypt an exchange is a shared
secret key. If one or more instances of the Crypto data format are configured with this key
the format can be used to encrypt the payload in one route (or part of one) and decrypted
in another. For example, using the Java DSL as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES"</span>, generator.generateKey());

from(<span class="code-quote">"direct:basic-encryption"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(cryptoFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>In Spring the dataformat is configured first and then used in routes </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;camelContext id=<span class="code-quote">"camel"</span>
xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag">&lt;dataFormats&gt;</span>
    <span class="code-tag">&lt;crypto id=<span class="code-quote">"basic"</span>
algorithm=<span class="code-quote">"DES"</span> keyRef=<span class="code-quote">"desKey"</span>
/&gt;</span>
  <span class="code-tag">&lt;/dataFormats&gt;</span>
    ...
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:basic-encryption"</span>
/&gt;</span>
    <span class="code-tag">&lt;marshal ref=<span class="code-quote">"basic"</span>
/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:encrypted"</span>
/&gt;</span>
    <span class="code-tag">&lt;unmarshal ref=<span class="code-quote">"basic"</span>
/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:unencrypted"</span>
/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h3><a name="Crypto-SpecifyingtheEncryptionAlgorithm"></a>Specifying the
Encryption Algorithm</h3>

<p>Changing the algorithm is a matter of supplying the JCE algorithm name. If you change
the algorithm you will need to use a compatible key.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES"</span>, generator.generateKey());
cryptoFormat.setShouldAppendHMAC(<span class="code-keyword">true</span>);
cryptoFormat.setMacAlgorithm(<span class="code-quote">"HmacMD5"</span>);

from(<span class="code-quote">"direct:hmac-algorithm"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(cryptoFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<h3><a name="Crypto-SpecifyinganInitializationVector"></a>Specifying an
Initialization Vector</h3>

<p>Some crypto algorhithms, particularly block algorithms, require configuration with
an initial block of data known as an Initialization Vector. In the JCE this is passed as an
AlgorithmParameterSpec when the Cipher is initialized. To use such a vector with the CryptoDataFormat
you can configure it with a byte[] contianing the required data e.g.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);
<span class="code-object">byte</span>[] initializationVector = <span class="code-keyword">new</span>
<span class="code-object">byte</span>[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07};

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES/CBC/PKCS5Padding"</span>, generator.generateKey());
cryptoFormat.setInitializationVector(initializationVector);

from(<span class="code-quote">"direct:init-vector"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(cryptoFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or with spring, suppling a reference to a byte[]</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;crypto id=<span class="code-quote">"initvector"</span>
algorithm=<span class="code-quote">"DES/CBC/PKCS5Padding"</span> keyRef=<span
class="code-quote">"desKey"</span> initVectorRef=<span class="code-quote">"initializationVector"</span>
/&gt;</span>
</pre>
</div></div>

<p>The same vector is required in both the encryption and decryption phases. As it is
not necessary to keep the IV a secret, the DataFormat allows for it to be inlined into the
encrypted data and subsequently read out in the decryption phase to initialize the Cipher.
To inline the IV set the /oinline flag.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);
<span class="code-object">byte</span>[] initializationVector = <span class="code-keyword">new</span>
<span class="code-object">byte</span>[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07};
SecretKey key = generator.generateKey();

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES/CBC/PKCS5Padding"</span>, key);
cryptoFormat.setInitializationVector(initializationVector);
cryptoFormat.setShouldInlineInitializationVector(<span class="code-keyword">true</span>);
CryptoDataFormat decryptFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES/CBC/PKCS5Padding"</span>, key);
decryptFormat.setShouldInlineInitializationVector(<span class="code-keyword">true</span>);

from(<span class="code-quote">"direct:inline"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(decryptFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or with spring.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">&lt;crypto id=<span class="code-quote">"inline"</span>
algorithm=<span class="code-quote">"DES/CBC/PKCS5Padding"</span> keyRef=<span
class="code-quote">"desKey"</span> initVectorRef=<span class="code-quote">"initializationVector"</span>
  inline=<span class="code-quote">"true"</span> /&gt;
<span class="code-tag">&lt;crypto id=<span class="code-quote">"inline-decrypt"</span>
algorithm=<span class="code-quote">"DES/CBC/PKCS5Padding"</span> keyRef=<span
class="code-quote">"desKey"</span> inline=<span class="code-quote">"true"</span>
/&gt;</span>
</pre>
</div></div>

<p>For more information of the use of Initialization Vectors, consult</p>

<ul>
	<li><a href="http://en.wikipedia.org/wiki/Initialization_vector" class="external-link"
rel="nofollow">http://en.wikipedia.org/wiki/Initialization_vector</a></li>
	<li><a href="http://www.herongyang.com/Cryptography/" class="external-link" rel="nofollow">http://www.herongyang.com/Cryptography/</a></li>
	<li><a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation" class="external-link"
rel="nofollow">http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation</a></li>
</ul>


<h3><a name="Crypto-HashedMessageAuthenticationCodes%28HMAC%29"></a>Hashed
Message Authentication Codes (HMAC)</h3>

<p>To avoid attacks against the encrypted data while it is in transit the CryptoDataFormat
can also calculate a Message Authentication Code forthe 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 <a href="http://en.wikipedia.org/wiki/HMAC" class="external-link"
rel="nofollow">http://en.wikipedia.org/wiki/HMAC</a></p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES"</span>, generator.generateKey());
cryptoFormat.setShouldAppendHMAC(<span class="code-keyword">true</span>);

from(<span class="code-quote">"direct:hmac"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(cryptoFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or with spring.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;crypto id=<span class="code-quote">"hmac"</span>
algorithm=<span class="code-quote">"DES"</span> keyRef=<span class="code-quote">"desKey"</span>
shouldAppendHMAC=<span class="code-quote">"true"</span> /&gt;</span>
</pre>
</div></div>

<p>By default the HMAC is calculated using the HmacSHA1 mac algorithm though this can
be easily changed by supplying a different algorithm name. See <a href="/confluence/pages/createpage.action?spaceKey=CAMEL&amp;title=here&amp;linkCreation=true&amp;fromPageId=17268915"
class="createlink">here</a> for how to check what algorithms are available through
the configured security providers</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">KeyGenerator generator = KeyGenerator.getInstance(<span class="code-quote">"DES"</span>);

CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span> CryptoDataFormat(<span
class="code-quote">"DES"</span>, generator.generateKey());
cryptoFormat.setShouldAppendHMAC(<span class="code-keyword">true</span>);
cryptoFormat.setMacAlgorithm(<span class="code-quote">"HmacMD5"</span>);

from(<span class="code-quote">"direct:hmac-algorithm"</span>)
    .marshal(cryptoFormat)
    .to(<span class="code-quote">"mock:encrypted"</span>)
    .unmarshal(cryptoFormat)
    .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or with spring.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;crypto id=<span class="code-quote">"hmac-algorithm"</span>
algorithm=<span class="code-quote">"DES"</span> keyRef=<span class="code-quote">"desKey"</span>
macAlgorithm=<span class="code-quote">"HmacMD5"</span> shouldAppendHMAC=<span
class="code-quote">"true"</span> /&gt;</span>
</pre>
</div></div>

<h3><a name="Crypto-SupplyingKeysDynamically"></a>Supplying Keys Dynamically</h3>

<p>When using a Recipient list or similar EIP the recipient of an exchange can vary
dynamically. Using the same key across all recipients may neither be feasible or desirable.
It would be useful to be able to specify keys dynamically on a per exchange basis. The exchange
could then be dynamically enriched with the key of its target recipient before being processed
by the data format. To facilitate this the DataFormat allow for keys to be supplied dynamically
via the message headers below </p>

<ul>
	<li><tt>CryptoDataFormat.KEY</tt> <tt>"CamelCryptoKey"</tt></li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">CryptoDataFormat cryptoFormat = <span class="code-keyword">new</span>
CryptoDataFormat(<span class="code-quote">"DES"</span>, <span class="code-keyword">null</span>);
/**
 * Note: the header containing the key should be cleared after
 * marshalling to stop it from leaking by accident and
 * potentially being compromised. The processor version below is
 * arguably better as the key is left in the header when you use
 * the DSL leaks the fact that camel encryption was used.
 */
from(<span class="code-quote">"direct:key-in-header-encrypt"</span>)
    .marshal(cryptoFormat)
    .removeHeader(CryptoDataFormat.KEY)
    .to(<span class="code-quote">"mock:encrypted"</span>);

from(<span class="code-quote">"direct:key-in-header-decrypt"</span>).unmarshal(cryptoFormat).process(<span
class="code-keyword">new</span> Processor() {
    <span class="code-keyword">public</span> void process(Exchange exchange) <span
class="code-keyword">throws</span> Exception {
        exchange.getIn().getHeaders().remove(CryptoDataFormat.KEY);
        exchange.getOut().copyFrom(exchange.getIn());
    }
}).to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or with spring.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;crypto id=<span class="code-quote">"nokey"</span>
algorithm=<span class="code-quote">"DES"</span> /&gt;</span>
</pre>
</div></div>

<h3><a name="Crypto-PGPDataFormatOptions"></a>PGPDataFormat Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyUserid</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The userid of the key in the PGP keyring. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Password used when opening the private key (not used for encryption).
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>keyFileName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Filename of the keyring; must be accessible as a classpath
resource (but you can specify a location in the file system by using the "file:" prefix).
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>signatureKeyUserid</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Optional userid of the
key in the PGP keyring to use for signing (during encryption) or signature verification (during
decryption) .</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>signaturePassword</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Optional password used
when opening the private key used for signing (during encryption). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>signatureKeyFileName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Optional filename of
the keyring to use for signing (during encryption) or for signature verification (during decryption);
must be accessible as a classpath resource (but you can specify a location in the file system
by using the "file:" prefix). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>armored</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> This option will cause PGP to base64 encode the encrypted
text, making it available for copy/paste, etc. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>integrity</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Adds an integrity check/sign into the encryption file. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Crypto-PGPDataFormatMessageHeaders"></a>PGPDataFormat Message
Headers</h3>
<p>You can override the PGPDataFormat options by applying below headers into message
dynamically.</p>

<div class="confluenceTableSmall"></div>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatKeyFileName</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Filename of the keyring;
will override existing setting directly on the PGPDataFormat. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatKeyUserid</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> The userid of the key
in the PGP keyring; will override existing setting directly on the PGPDataFormat. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatKeyPassword</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Password used when opening
the private key; will override existing setting directly on the PGPDataFormat. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatSignatureKeyFileName</tt>
</td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Filename of the signature
keyring; will override existing setting directly on the PGPDataFormat. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatSignatureKeyUserid</tt>
</td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> The userid of the signature
key in the PGP keyring; will override existing setting directly on the PGPDataFormat. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelPGPDataFormatSignatureKeyPassword</tt>
</td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> <b>Since Camel 2.11.0</b> Password used when opening
the signature private key; will override existing setting directly on the PGPDataFormat. </td>
</tr>
</tbody></table>
</div>


<h3><a name="Crypto-EncryptingwithPGPDataFormat"></a>Encrypting with PGPDataFormat</h3>

<p>The following sample uses the popular PGP format for encrypting/decypting files using
the libraries from <a href="http://www.bouncycastle.org/java.html" class="external-link"
rel="nofollow">http://www.bouncycastle.org/java.html</a>.  For help managing your
keyring see the next section</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// Public Key FileName
</span><span class="code-object">String</span> keyFileName = getKeyFileName();
<span class="code-comment">// Private Key FileName
</span><span class="code-object">String</span> keyFileNameSec = getKeyFileNameSec();
<span class="code-comment">// Keyring Userid Used to Encrypt
</span><span class="code-object">String</span> keyUserid = getKeyUserId();
<span class="code-comment">// Private key password
</span><span class="code-object">String</span> keyPassword = getKeyPassword();

from(<span class="code-quote">"direct:inline"</span>)
        .marshal().pgp(keyFileName, keyUserid)
        .to(<span class="code-quote">"mock:encrypted"</span>)
        .unmarshal().pgp(keyFileNameSec, keyUserid, keyPassword)
        .to(<span class="code-quote">"mock:unencrypted"</span>);
</pre>
</div></div>

<p>or using spring</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;dataFormats&gt;</span>
  <span class="code-tag"><span class="code-comment">&lt;!-- will load the
file from classpath by default, but you can prefix with file: to load from file system --&gt;</span></span>
  &lt;pgp id=<span class="code-quote">"encrypt"</span> keyFileName=<span
class="code-quote">"org/apache/camel/component/crypto/pubring.gpg"</span>
       keyUserid=<span class="code-quote">"sdude@nowhere.net"</span>/&gt;
  &lt;pgp id=<span class="code-quote">"decrypt"</span> keyFileName=<span
class="code-quote">"org/apache/camel/component/crypto/secring.gpg"</span>
       keyUserid=<span class="code-quote">"sdude@nowhere.net"</span> password=<span
class="code-quote">"sdude"</span>/&gt;
<span class="code-tag">&lt;/dataFormats&gt;</span>

<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:inline"</span>/&gt;</span>
  <span class="code-tag">&lt;marshal ref=<span class="code-quote">"encrypt"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:encrypted"</span>/&gt;</span>
  <span class="code-tag">&lt;unmarshal ref=<span class="code-quote">"decrypt"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:unencrypted"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="Crypto-Toworkwiththepreviousexampleyouneedthefollowing"></a>To
work with the previous example you need the following</h4>
<ul>
	<li>A public keyring file which contains the public keys used to encrypt the data</li>
	<li>A private keyring file which contains the keys used to decrypt the data</li>
	<li>The keyring password</li>
</ul>


<h4><a name="Crypto-Managingyourkeyring"></a>Managing your keyring</h4>
<p>To manage the keyring, I use the command line tools, I find this to be the simplest
approach in managing the keys.  There are also Java libraries available from <a href="http://www.bouncycastle.org/java.html"
class="external-link" rel="nofollow">http://www.bouncycastle.org/java.html</a> if
you would prefer to do it that way.</p>

<ol>
	<li>Install the command line utilities on linux
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">apt-get install gnupg</pre>
</div></div></li>
	<li>Create your keyring, entering a secure password
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">gpg --gen-key</pre>
</div></div></li>
	<li>If you need to import someone elses public key so that you can encrypt a file for
them.
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">gpg --<span class="code-keyword">import</span> &lt;filename.key</pre>
</div></div></li>
	<li>The following files should now exist and can be used to run the example
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">ls -l ~/.gnupg/pubring.gpg ~/.gnupg/secring.gpg</pre>
</div></div></li>
</ol>


<h3><a name="Crypto-Dependencies"></a>Dependencies</h3>

<p>To use the <a href="/confluence/display/CAMEL/Crypto" title="Crypto">Crypto</a>
dataformat in your camel routes you need to add the following dependency to your pom.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
  <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
  <span class="code-tag">&lt;artifactId&gt;</span>camel-crypto<span
class="code-tag">&lt;/artifactId&gt;</span>
  <span class="code-tag">&lt;version&gt;</span>2.9.0<span class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>


<h3><a name="Crypto-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a></li>
	<li><a href="/confluence/display/CAMEL/Crypto+%28Digital+Signatures%29" title="Crypto
(Digital Signatures)">Crypto &#40;Digital Signatures&#41;</a></li>
	<li><a href="http://www.bouncycastle.org/java.html" class="external-link" rel="nofollow">http://www.bouncycastle.org/java.html</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Crypto">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=17268915&revisedVersion=18&originalVersion=17">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Crypto?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message