You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/03/23 09:49:48 UTC

svn commit: r926499 [1/3] - in /camel/trunk: apache-camel/ apache-camel/src/main/descriptors/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/resources/org/apache/camel/mo...

Author: davsclaus
Date: Tue Mar 23 08:49:46 2010
New Revision: 926499

URL: http://svn.apache.org/viewvc?rev=926499&view=rev
Log:
CAMEL-2482: camel-crypto is a new component. Many thanks to Stephen Gargan for contribution.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java   (with props)
    camel/trunk/components/camel-crypto/
    camel/trunk/components/camel-crypto/pom.xml   (with props)
    camel/trunk/components/camel-crypto/src/
    camel/trunk/components/camel-crypto/src/main/
    camel/trunk/components/camel-crypto/src/main/java/
    camel/trunk/components/camel-crypto/src/main/java/org/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HMACAccumulator.java   (with props)
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/HexUtils.java   (with props)
    camel/trunk/components/camel-crypto/src/main/resources/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/LICENSE.txt   (with props)
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/NOTICE.txt   (with props)
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/sign
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/component/verify
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/
    camel/trunk/components/camel-crypto/src/main/resources/META-INF/services/org/apache/camel/dataformat/crypto
    camel/trunk/components/camel-crypto/src/test/
    camel/trunk/components/camel-crypto/src/test/java/
    camel/trunk/components/camel-crypto/src/test/java/org/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SignatureTests.java   (with props)
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/SpringSignatureTest.java   (with props)
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/CryptoDataFormatTest.java   (with props)
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HMACAccumulatorTest.java   (with props)
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/HexUtilsTest.java   (with props)
    camel/trunk/components/camel-crypto/src/test/java/org/apache/camel/converter/crypto/SpringCryptoDataFormatTest.java   (with props)
    camel/trunk/components/camel-crypto/src/test/resources/
    camel/trunk/components/camel-crypto/src/test/resources/.keystore   (with props)
    camel/trunk/components/camel-crypto/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-crypto/src/test/resources/org/
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml   (with props)
    camel/trunk/components/camel-crypto/src/test/resources/org/apache/camel/component/crypto/SpringSignatureTests.xml   (with props)
Modified:
    camel/trunk/apache-camel/pom.xml
    camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
    camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
    camel/trunk/components/pom.xml
    camel/trunk/parent/pom.xml

Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Tue Mar 23 08:49:46 2010
@@ -72,6 +72,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-crypto</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-csv</artifactId>
     </dependency>
     <dependency>

Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Tue Mar 23 08:49:46 2010
@@ -41,6 +41,7 @@
         <include>org.apache.camel:camel-castor</include>
         <include>org.apache.camel:camel-core</include>
         <include>org.apache.camel:camel-cometd</include>
+        <include>org.apache.camel:camel-crypto</include>
         <include>org.apache.camel:camel-csv</include>
         <include>org.apache.camel:camel-cxf</include>
         <include>org.apache.camel:camel-dozer</include>

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java Tue Mar 23 08:49:46 2010
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRoot
 import org.apache.camel.Processor;
 import org.apache.camel.model.dataformat.BindyDataFormat;
 import org.apache.camel.model.dataformat.CastorDataFormat;
+import org.apache.camel.model.dataformat.CryptoDataFormat;
 import org.apache.camel.model.dataformat.CsvDataFormat;
 import org.apache.camel.model.dataformat.FlatpackDataFormat;
 import org.apache.camel.model.dataformat.GzipDataFormat;
@@ -58,6 +59,7 @@ public class MarshalDefinition extends O
     @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
     @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
     @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+    @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
     @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
     @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
     @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
@@ -66,7 +68,7 @@ public class MarshalDefinition extends O
     @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
     @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
-    @XmlElement(required = false, name = "string", type = StringDataFormat.class), 
+    @XmlElement(required = false, name = "string", type = StringDataFormat.class),
     @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
     @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
     @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java Tue Mar 23 08:49:46 2010
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlRoot
 import org.apache.camel.Processor;
 import org.apache.camel.model.dataformat.BindyDataFormat;
 import org.apache.camel.model.dataformat.CastorDataFormat;
+import org.apache.camel.model.dataformat.CryptoDataFormat;
 import org.apache.camel.model.dataformat.CsvDataFormat;
 import org.apache.camel.model.dataformat.FlatpackDataFormat;
 import org.apache.camel.model.dataformat.GzipDataFormat;
@@ -59,6 +60,7 @@ public class UnmarshalDefinition extends
     @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
     @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
     @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+    @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
     @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
     @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
     @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
@@ -68,7 +70,7 @@ public class UnmarshalDefinition extends
     @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
     @XmlElement(required = false, name = "string", type = StringDataFormat.class),
-    @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),    
+    @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
     @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
     @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
     @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.model.dataformat;
+
+import java.security.Key;
+import java.security.spec.AlgorithmParameterSpec;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.ObjectHelper;
+
+@XmlRootElement(name = "crypto")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CryptoDataFormat extends DataFormatDefinition {
+    @XmlAttribute
+    private String algorithm;
+    @XmlAttribute
+    private String cryptoProvider;
+    @XmlAttribute
+    private String keyRef;
+    @XmlAttribute
+    private String initVectorRef;
+    @XmlAttribute
+    private String algorithmParameterRef;
+    @XmlAttribute
+    private Integer buffersize;
+    @XmlAttribute
+    private String macAlgorithm = "HmacSHA1";
+    @XmlAttribute
+    private Boolean shouldAppendHMAC;
+    @XmlAttribute
+    private Boolean inline;
+
+    public CryptoDataFormat() {
+        super("crypto");
+    }
+
+    @Override
+    protected DataFormat createDataFormat(RouteContext routeContext) {
+        DataFormat cryptoFormat = super.createDataFormat(routeContext);
+
+        if (ObjectHelper.isNotEmpty(keyRef)) {
+            Key key = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), keyRef, Key.class);
+            setProperty(cryptoFormat, "key", key);
+        }
+        if (ObjectHelper.isNotEmpty(algorithmParameterRef)) {
+            AlgorithmParameterSpec spec = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(),
+                    algorithmParameterRef, AlgorithmParameterSpec.class);
+            setProperty(cryptoFormat, "AlgorithmParameterSpec", spec);
+        }
+        if (ObjectHelper.isNotEmpty(initVectorRef)) {
+            byte[] iv = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), initVectorRef, byte[].class);
+            setProperty(cryptoFormat, "InitializationVector", iv);
+        }
+        return cryptoFormat;
+    }
+
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat) {
+        Boolean answer = ObjectHelper.toBoolean(shouldAppendHMAC);
+        if (answer != null && !answer) {
+            setProperty(dataFormat, "shouldAppendHMAC", Boolean.FALSE);
+        } else {
+            setProperty(dataFormat, "shouldAppendHMAC", Boolean.TRUE);
+        }
+        answer = ObjectHelper.toBoolean(inline);
+        if (answer != null && answer) {
+            setProperty(dataFormat, "shouldInlineInitializationVector", Boolean.TRUE);
+        } else {
+            setProperty(dataFormat, "shouldInlineInitializationVector", Boolean.FALSE);
+        }
+        if (algorithm != null) {
+            setProperty(dataFormat, "algorithm", algorithm);
+        }
+        if (cryptoProvider != null) {
+            setProperty(dataFormat, "cryptoProvider", cryptoProvider);
+        }
+        if (macAlgorithm != null) {
+            setProperty(dataFormat, "macAlgorithm", macAlgorithm);
+        }
+        if (buffersize != null) {
+            setProperty(dataFormat, "buffersize", buffersize);
+        }
+    }
+
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+
+    public void setCryptoProvider(String cryptoProvider) {
+        this.cryptoProvider = cryptoProvider;
+    }
+
+    public void setKeyReference(String keyReference) {
+        this.keyRef = keyReference;
+    }
+
+    public void setInitVectorRef(String initVectorRef) {
+        this.initVectorRef = initVectorRef;
+    }
+
+    public void setAlgorithmParameterRef(String algorithmParameterRef) {
+        this.algorithmParameterRef = algorithmParameterRef;
+    }
+
+    public void setBuffersize(Integer buffersize) {
+        this.buffersize = buffersize;
+    }
+
+    public void setMacAlgorithm(String macAlgorithm) {
+        this.macAlgorithm = macAlgorithm;
+    }
+
+    public void setShouldAppendHMAC(Boolean shouldAppendHMAC) {
+        this.shouldAppendHMAC = shouldAppendHMAC;
+    }
+
+    public void setShouldInlineInitVector(Boolean inline) {
+        this.inline = inline;
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/CryptoDataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java Tue Mar 23 08:49:46 2010
@@ -39,6 +39,7 @@ public class DataFormatsDefinition {
     @XmlElements({
         @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
         @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
+        @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
         @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
         @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
         @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
@@ -50,7 +51,7 @@ public class DataFormatsDefinition {
         @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
         @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
         @XmlElement(required = false, name = "string", type = StringDataFormat.class),
-        @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),        
+        @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
         @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
         @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
         @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}

Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=926499&r1=926498&r2=926499&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index Tue Mar 23 08:49:46 2010
@@ -18,6 +18,7 @@ BindyDataFormat
 BindyType
 CastorDataFormat
 CsvDataFormat
+CryptoDataFormat
 DataFormatsDefinition
 FlatpackDataFormat
 GzipDataFormat

Added: camel/trunk/components/camel-crypto/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/pom.xml?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/pom.xml (added)
+++ camel/trunk/components/camel-crypto/pom.xml Tue Mar 23 08:49:46 2010
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-crypto</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: Crypto</name>
+    <description>Camel Cryptographic Support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>
+            org.apache.camel.component.crypto.*,
+            org.apache.camel.converter.crypto.*
+        </camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>bouncycastle</groupId>
+            <artifactId>bcprov-jdk15</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <version>${pom.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <version>${pom.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
+

Propchange: camel/trunk/components/camel-crypto/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-crypto/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * <code>DigitalSignatureComponent</code>
+ */
+@SuppressWarnings("unchecked")
+public class DigitalSignatureComponent extends DefaultComponent {
+
+    private DigitalSignatureConfiguration configuration;
+
+    public DigitalSignatureComponent() {
+    }
+
+    public DigitalSignatureComponent(CamelContext context) {
+        super(context);
+    }
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+        ObjectHelper.notNull(getCamelContext(), "CamelContext");
+
+        DigitalSignatureConfiguration config = getConfiguration().copy();
+        setProperties(config, parameters);
+        config.setCamelContext(getCamelContext());
+
+        return new DigitalSignatureEndpoint(uri, this, config);
+    }
+
+    public DigitalSignatureConfiguration getConfiguration() {
+        if (configuration == null) {
+            configuration = new DigitalSignatureConfiguration();
+        }
+        return configuration;
+    }
+
+    public void setConfiguration(DigitalSignatureConfiguration configuration) {
+        this.configuration = configuration;
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,402 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto;
+
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.cert.Certificate;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.RuntimeCamelException;
+
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE;
+
+public class DigitalSignatureConfiguration implements Cloneable, CamelContextAware {
+
+    private PrivateKey privateKey;
+    private KeyStore keystore;
+    private SecureRandom secureRandom;
+    private String algorithm = "DSA";
+    private Integer bufferSize = new Integer(2048);
+    private String provider;
+    private String signatureHeaderName;
+    private String alias;
+    private char[] password;
+    private PublicKey publicKey;
+    private Certificate certificate;
+    private CamelContext context;
+
+    /** references that should be resolved when the context changes */
+    private String publicKeyName;
+    private String certificateName;
+    private String privateKeyName;
+    private String keystoreName;
+    private String randomName;
+    private boolean clearHeaders;
+
+    public DigitalSignatureConfiguration copy() {
+        try {
+            return (DigitalSignatureConfiguration)clone();
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+    public CamelContext getCamelContext() {
+        return context;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        this.context = camelContext;
+        // try to retrieve the references once the context is available.
+        setKeystore(keystoreName);
+        setPublicKey(publicKeyName);
+        setPrivateKey(privateKeyName);
+        setCertificate(certificateName);
+        setSecureRandom(randomName);
+    }
+
+    /**
+     * Gets the JCE name of the Algorithm that should be used for the signer.
+     */
+    public String getAlgorithm() {
+        return algorithm;
+    }
+
+    /**
+     * Sets the JCE name of the Algorithm that should be used for the signer.
+     */
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+
+    /**
+     * Gets the alias used to query the KeyStore for keys and {@link java.security.cert.Certificate Certificates}
+     * to be used in signing and verifying exchanges. This value can be provided at runtime via the message header
+     * {@link org.apache.camel.component.crypto.DigitalSignatureConstants#KEYSTORE_ALIAS}
+     */
+    public String getAlias() {
+        return alias;
+    }
+
+    /**
+     * Sets the alias used to query the KeyStore for keys and {@link java.security.cert.Certificate Certificates}
+     * to be used in signing and verifying exchanges. This value can be provided at runtime via the message header
+     * {@link org.apache.camel.component.crypto.DigitalSignatureConstants#KEYSTORE_ALIAS}
+     */
+    public void setAlias(String alias) {
+        this.alias = alias;
+    }
+
+    /**
+     * Get the PrivateKey that should be used to sign the exchange
+     */
+    public PrivateKey getPrivateKey() throws Exception {
+        return getPrivateKey(alias, password);
+    }
+
+    /**
+     * Get the PrivateKey that should be used to sign the signature in the
+     * exchange using the supplied alias.
+     *
+     * @param alias the alias used to retrieve the Certificate from the keystore.
+     */
+    public PrivateKey getPrivateKey(String alias) throws Exception {
+        return getPrivateKey(alias, password);
+    }
+
+    /**
+     * Get the PrivateKey that should be used to sign the signature in the
+     * exchange using the supplied alias.
+     *
+     * @param alias the alias used to retrieve the Certificate from the keystore.
+     */
+    public PrivateKey getPrivateKey(String alias, char[] password) throws Exception {
+        PrivateKey pk = null;
+        if (alias != null && keystore != null) {
+            pk = (PrivateKey)keystore.getKey(alias, password);
+        }
+        if (pk == null) {
+            pk = privateKey;
+        }
+        return pk;
+    }
+
+    /**
+     * Set the PrivateKey that should be used to sign the exchange
+     *
+     * @param privateKey the key with with to sign the exchange.
+     */
+    public void setPrivateKey(PrivateKey privateKey) {
+        this.privateKey = privateKey;
+    }
+
+    /**
+     * Sets the reference name for a PrivateKey that can be fond in the registry.
+     */
+    public void setPrivateKey(String privateKeyName) {
+        if (context != null && privateKeyName != null) {
+            PrivateKey pk = context.getRegistry().lookup(privateKeyName, PrivateKey.class);
+            if (pk != null) {
+                setPrivateKey(pk);
+            }
+        }
+        if (privateKeyName != null) {
+            this.privateKeyName = privateKeyName;
+        }
+    }
+
+    /**
+     * Set the PublicKey that should be used to verify the signature in the exchange.
+     */
+    public void setPublicKey(PublicKey publicKey) {
+        this.publicKey = publicKey;
+    }
+
+    /**
+     * Sets the reference name for a publicKey that can be fond in the registry.
+     */
+    public void setPublicKey(String publicKeyName) {
+        if (context != null && publicKeyName != null) {
+            PublicKey pk = context.getRegistry().lookup(publicKeyName, PublicKey.class);
+            if (pk != null) {
+                setPublicKey(pk);
+            }
+        }
+        if (publicKeyName != null) {
+            this.publicKeyName = publicKeyName;
+        }
+    }
+
+    /**
+     * get the PublicKey that should be used to verify the signature in the exchange.
+     */
+    public PublicKey getPublicKey() {
+        return publicKey;
+    }
+
+    /**
+     * Set the Certificate that should be used to verify the signature in the
+     * exchange. If a {@link KeyStore} has been configured then this will
+     * attempt to retrieve the {@link Certificate}from it using hte supplied
+     * alias. If either the alias or the Keystore is invalid then the configured
+     * certificate will be returned
+     *
+     * @param alias the alias used to retrieve the Certificate from the keystore.
+     */
+    public Certificate getCertificate(String alias) throws Exception {
+        Certificate cert = null;
+        if (alias != null && keystore != null) {
+            cert = keystore.getCertificate(alias);
+        }
+        if (cert == null) {
+            cert = certificate;
+        }
+        return cert;
+    }
+
+    /**
+     * Get the explicitly configured {@link Certificate} that should be used to
+     * verify the signature in the exchange.
+     */
+    public Certificate getCertificate() throws Exception {
+        return certificate;
+    }
+
+    /**
+     * Set the Certificate that should be used to verify the signature in the
+     * exchange based on its payload.
+     */
+    public void setCertificate(Certificate certificate) {
+
+        this.certificate = certificate;
+    }
+
+    /**
+     * Sets the reference name for a PrivateKey that can be fond in the registry.
+     */
+    public void setCertificate(String certificateName) {
+        if (context != null && certificateName != null) {
+            Certificate certificate = context.getRegistry().lookup(certificateName, Certificate.class);
+            if (certificate != null) {
+                setCertificate(certificate);
+            }
+        }
+        if (certificateName != null) {
+            this.certificateName = certificateName;
+        }
+    }
+
+    /**
+     * Gets the KeyStore that can contain keys and Certficates for use in
+     * signing and verifying exchanges. A {@link KeyStore} is typically used
+     * with an alias, either one supplied in the Route definition or dynamically
+     * via the message header "CamelSignatureKeyStoreAlias". If no alias is
+     * supplied and there is only a single entry in the Keystore, then this
+     * single entry will be used.
+     */
+    public KeyStore getKeystore() {
+        return keystore;
+    }
+
+    /**
+     * Sets the KeyStore that can contain keys and Certficates for use in
+     * signing and verifying exchanges. A {@link KeyStore} is typically used
+     * with an alias, either one supplied in the Route definition or dynamically
+     * via the message header "CamelSignatureKeyStoreAlias". If no alias is
+     * supplied and there is only a single entry in the Keystore, then this
+     * single entry will be used.
+     */
+    public void setKeystore(KeyStore keystore) {
+        this.keystore = keystore;
+    }
+
+    /**
+     * Sets the reference name for a Keystore that can be fond in the registry.
+     */
+    public void setKeystore(String keystoreName) {
+        if (context != null && keystoreName != null) {
+            KeyStore keystore = context.getRegistry().lookup(keystoreName, KeyStore.class);
+            if (keystore != null) {
+                setKeystore(keystore);
+            }
+        }
+        if (keystoreName != null) {
+            this.keystoreName = keystoreName;
+        }
+    }
+
+    /**
+     * Gets the password used to access an aliased {@link PrivateKey} in the KeyStore.
+     */
+    public char[] getPassword() {
+        return password;
+    }
+
+    /**
+     * Sets the password used to access an aliased {@link PrivateKey} in the KeyStore.
+     */
+    public void setPassword(char[] password) {
+        this.password = password;
+    }
+
+    /**
+     * Get the SecureRandom used to initialize the Signature service
+     */
+    public SecureRandom getSecureRandom() {
+        return secureRandom;
+    }
+
+    /**
+     * Sets the reference name for a SecureRandom that can be fond in the registry.
+     */
+    public void setSecureRandom(String randomName) {
+        if (context != null && randomName != null) {
+            SecureRandom random = context.getRegistry().lookup(randomName, SecureRandom.class);
+            if (keystore != null) {
+                setSecureRandom(random);
+            }
+        }
+        if (randomName != null) {
+            this.randomName = randomName;
+        }
+    }
+
+    /**
+     * Set the SecureRandom used to initialize the Signature service
+     *
+     * @param secureRandom the random used to init the Signature service
+     */
+    public void setSecureRandom(SecureRandom secureRandom) {
+        this.secureRandom = secureRandom;
+    }
+
+    /**
+     * Get the size of the buffer used to read in the Exchange payload data.
+     */
+    public Integer getBufferSize() {
+        return bufferSize;
+    }
+
+    /**
+     * Set the size of the buffer used to read in the Exchange payload data.
+     */
+    public void setBufferSize(Integer bufferSize) {
+        this.bufferSize = bufferSize;
+    }
+
+    /**
+     * Get the id of the security provider that provides the configured
+     * {@link Signature} algorithm.
+     */
+    public String getProvider() {
+        return provider;
+    }
+
+    /**
+     * Set the id of the security provider that provides the configured
+     * {@link Signature} algorithm.
+     *
+     * @param provider the id of the security provider
+     */
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    /**
+     * Get the name of the message header that should be used to store the
+     * base64 encoded signature. This defaults to 'CamelDigitalSignature'
+     */
+    public String getSignatureHeader() {
+        return signatureHeaderName != null ? signatureHeaderName : SIGNATURE;
+    }
+
+    /**
+     * Set the name of the message header that should be used to store the
+     * base64 encoded signature. This defaults to 'CamelDigitalSignature'
+     */
+    public void setSignatureHeader(String signatureHeaderName) {
+        this.signatureHeaderName = signatureHeaderName;
+    }
+
+    /**
+     * Determines if the Signature specific headers be cleared after signing and
+     * verification. Defaults to true, and should only be made otherwise at your
+     * extreme peril as vital private information such as Keys and passwords may
+     * escape if unset.
+     *
+     * @return true if the Signature headers should be unset, false otherwise
+     */
+    public boolean getClearHeaders() {
+        return clearHeaders;
+    }
+
+    /**
+     * Determines if the Signature specific headers be cleared after signing and
+     * verification. Defaults to true, and should only be made otherwise at your
+     * extreme peril as vital private information such as Keys and passwords may
+     * escape if unset.
+     */
+    public void setClearHeaders(boolean clearHeaders) {
+        this.clearHeaders = clearHeaders;
+    }
+
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto;
+
+/**
+ * <code>DigitalSignatureConstants</code> contains Constants for use as Message
+ * header keys.
+ */
+public interface DigitalSignatureConstants {
+
+    String SIGNATURE_PRIVATE_KEY = "CamelSignaturePrivateKey";
+    String SIGNATURE_PUBLIC_KEY_OR_CERT = "CamelSignaturePublicKeyOrCert";
+    String SIGNATURE = "CamelDigitalSignature";
+    String KEYSTORE_ALIAS = "CamelSignatureKeyStoreAlias";
+    String KEYSTORE_PASSWORD = "CamelSignatureKeyStorePassword";
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConstants.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,163 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto;
+
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.cert.Certificate;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.crypto.processor.SigningProcessor;
+import org.apache.camel.component.crypto.processor.VerifyingProcessor;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * <code>DigitalSignatureEndpoint</code>
+ */
+public class DigitalSignatureEndpoint extends DefaultEndpoint {
+    private DigitalSignatureConfiguration configuration;
+
+    public DigitalSignatureEndpoint(String uri, DigitalSignatureComponent component, DigitalSignatureConfiguration configuration) {
+        super(uri, component);
+        this.configuration = configuration;
+    }
+
+    public Producer createProducer() throws Exception {
+        return getEndpointUri().startsWith("sign")
+            ? new DigitalSignatureProducer(this, new SigningProcessor(configuration)) : new DigitalSignatureProducer(this, new VerifyingProcessor(configuration));
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        throw new UnsupportedOperationException("Digital Signatures endpoints are not meant to be consumed from. They are meant be used as an intermediate endpoints");
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public Object getManagedObject(DigitalSignatureEndpoint endpoint) {
+        return this;
+    }
+
+    public void setConfiguration(DigitalSignatureConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    public DigitalSignatureConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    public PublicKey getPublicKey() throws Exception {
+        return getConfiguration().getPublicKey();
+    }
+
+    public void setPublicKey(PublicKey publicKey) {
+        getConfiguration().setPublicKey(publicKey);
+    }
+
+    public void setPublicKey(String publicKeyName) {
+        getConfiguration().setPublicKey(publicKeyName);
+    }
+
+    public Certificate getCertificate() throws Exception {
+        return getConfiguration().getCertificate();
+    }
+
+    public PrivateKey getPrivateKey() throws Exception {
+        return getConfiguration().getPrivateKey();
+    }
+
+    public void setPrivateKey(PrivateKey privateKey) {
+        getConfiguration().setPrivateKey(privateKey);
+    }
+
+    public KeyStore getKeystore() {
+        return getConfiguration().getKeystore();
+    }
+
+    public void setKeystore(KeyStore keystore) {
+        getConfiguration().setKeystore(keystore);
+    }
+
+    public char[] getPassword() {
+        return getConfiguration().getPassword();
+    }
+
+    public void setKeyPassword(char[] keyPassword) {
+        getConfiguration().setPassword(keyPassword);
+    }
+
+    public SecureRandom getSecureRandom() {
+        return getConfiguration().getSecureRandom();
+    }
+
+    public void setSecureRandom(SecureRandom secureRandom) {
+        getConfiguration().setSecureRandom(secureRandom);
+    }
+
+    public String getAlgorithm() {
+        return getConfiguration().getAlgorithm();
+    }
+
+    public void setAlgorithm(String algorithm) {
+        getConfiguration().setAlgorithm(algorithm);
+    }
+
+    public Integer getBuffersize() {
+        return getConfiguration().getBufferSize();
+    }
+
+    public void setBuffersize(Integer buffersize) {
+        getConfiguration().setBufferSize(buffersize);
+    }
+
+    public String getProvider() {
+        return getConfiguration().getProvider();
+    }
+
+    public void setProvider(String provider) {
+        getConfiguration().setProvider(provider);
+    }
+
+    public String getSignatureHeader() {
+        return getConfiguration().getSignatureHeader();
+    }
+
+    public void setSignatureHeader(String signatureHeaderName) {
+        getConfiguration().setSignatureHeader(signatureHeaderName);
+    }
+
+    public String getAlias() {
+        return getConfiguration().getAlias();
+    }
+
+    public void setAlias(String alias) {
+        getConfiguration().setAlias(alias);
+    }
+
+    public boolean getClearHeaders() {
+        return getConfiguration().getClearHeaders();
+    }
+
+    public void setClearHeaders(boolean clearHeaders) {
+        getConfiguration().setClearHeaders(clearHeaders);
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureEndpoint.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.crypto.processor.DigitalSignatureProcessor;
+import org.apache.camel.impl.DefaultProducer;
+/**
+ * <code>DigitalSignatureProducer</code>
+ */
+public class DigitalSignatureProducer extends DefaultProducer {
+
+    private DigitalSignatureProcessor processor;
+
+    public DigitalSignatureProducer(DigitalSignatureEndpoint endpoint, DigitalSignatureProcessor processor) {
+        super(endpoint);
+        this.processor = processor;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        try {
+            processor.process(exchange);
+        } catch (Exception e) {
+            exchange.setException(e);
+        }
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureProducer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto.processor;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Signature;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.crypto.DigitalSignatureConfiguration;
+import org.apache.camel.component.crypto.DigitalSignatureConstants;
+import org.apache.camel.util.ExchangeHelper;
+
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.KEYSTORE_ALIAS;
+
+public abstract class DigitalSignatureProcessor implements Processor {
+
+    protected DigitalSignatureConfiguration config;
+
+    public DigitalSignatureProcessor(DigitalSignatureConfiguration configuration) {
+        this.config = configuration;
+    }
+
+    public void calculateSignature(Exchange exchange, Signature signer) throws Exception {
+        Object payload = exchange.getIn().getBody();
+        if (payload != null) {
+            InputStream payloadStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, payload);
+            byte[] buffer = new byte[config.getBufferSize()];
+            int read;
+            while ((read = payloadStream.read(buffer)) > 0) {
+                signer.update(buffer, 0, read);
+            }
+        }
+    }
+
+    protected String getAlias(Exchange exchange) throws Exception {
+        KeyStore keystore = config.getKeystore();
+        if (keystore != null) {
+            String alias = exchange.getIn().getHeader(KEYSTORE_ALIAS, String.class);
+            if (alias == null) {
+                alias = config.getAlias();
+            }
+
+            // if there is only one entry then use it. Document this well
+            if (alias == null && keystore.size() == 1) {
+                alias = keystore.aliases().nextElement();
+            }
+            return alias;
+        }
+        return null;
+    }
+
+    public void setConfig(DigitalSignatureConfiguration config) {
+        this.config = config;
+    }
+
+    protected Signature createSignatureService() throws NoSuchAlgorithmException, NoSuchProviderException {
+        String algorithm = config.getAlgorithm();
+        String provider = config.getProvider();
+        Signature signer = provider == null ? Signature.getInstance(algorithm) : Signature.getInstance(algorithm, provider);
+        return signer;
+    }
+
+    protected void clearMessageHeaders(Message in) {
+        if (config.getClearHeaders()) {
+            Map<String, Object> headers = in.getHeaders();
+            for (Field f : DigitalSignatureConstants.class.getFields()) {
+                headers.remove(f.getName());
+            }
+        }
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/DigitalSignatureProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto.processor;
+
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.SecureRandom;
+import java.security.Signature;
+import static java.lang.String.format;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.crypto.DigitalSignatureConfiguration;
+import org.apache.camel.component.crypto.DigitalSignatureConstants;
+import org.apache.commons.codec.binary.Base64;
+
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE_PRIVATE_KEY;
+
+public class SigningProcessor extends DigitalSignatureProcessor {
+
+    public SigningProcessor(DigitalSignatureConfiguration configuration) {
+        super(configuration);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        Signature service = initSignatureService(exchange);
+        calculateSignature(exchange, service);
+        byte[] signature = service.sign();
+
+        Message in = exchange.getIn();
+        clearMessageHeaders(in);
+        Message out = exchange.getOut();
+        out.copyFrom(in);
+        out.setHeader(config.getSignatureHeader(), new Base64().encode(signature));
+    }
+
+    protected Signature initSignatureService(Exchange exchange) throws Exception {
+        PrivateKey pk = getPrivateKeyFromKeystoreOrExchange(exchange);
+        SecureRandom random = config.getSecureRandom();
+        Signature service = createSignatureService();
+        if (random != null) {
+            service.initSign(pk, random);
+        } else {
+            service.initSign(pk);
+        }
+        return service;
+    }
+
+    private PrivateKey getPrivateKeyFromKeystoreOrExchange(Exchange exchange) throws Exception {
+        PrivateKey pk = config.getPrivateKey(getAlias(exchange), getKeyPassword(exchange));
+
+        if (pk == null) {
+            pk = exchange.getIn().getHeader(SIGNATURE_PRIVATE_KEY, PrivateKey.class);
+            if (pk == null) {
+                throw new IllegalStateException(format("Cannot sign message as no Private Key has been supplied. Either supply one in"
+                                                       + " the route definition sign(keystore, alias) or sign(privateKey) or via the message header '%s'", SIGNATURE_PRIVATE_KEY));
+            }
+        }
+        return pk;
+    }
+
+    protected char[] getKeyPassword(Exchange exchange) throws Exception {
+        KeyStore keystore = config.getKeystore();
+        char[] password = null;
+        if (keystore != null) {
+            password = exchange.getIn().getHeader(DigitalSignatureConstants.KEYSTORE_PASSWORD, char[].class);
+            if (password == null) {
+                password = config.getPassword();
+            }
+        }
+        return password;
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/SigningProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.crypto.processor;
+
+import java.security.PublicKey;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.cert.Certificate;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.crypto.DigitalSignatureConfiguration;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.commons.codec.binary.Base64;
+
+import static org.apache.camel.component.crypto.DigitalSignatureConstants.SIGNATURE_PUBLIC_KEY_OR_CERT;
+
+/**
+ * <code>VerifyingProcessor</code>
+ */
+public class VerifyingProcessor extends DigitalSignatureProcessor {
+
+    public VerifyingProcessor(DigitalSignatureConfiguration configuration) {
+        super(configuration);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        Signature signer = createSignatureService();
+        Certificate cert = getCertificate(exchange);
+        if (cert == null) {
+            PublicKey pk = getPublicKeyOrCertificateFromHeader(exchange, PublicKey.class, config.getPublicKey());
+            if (pk == null) {
+                throw new IllegalStateException(String.format("Cannot verify signature as no Public Key or Certificate has been supplied."
+                        + " Either supply one in the route definition or via the message header '%s'", SIGNATURE_PUBLIC_KEY_OR_CERT));
+            }
+            signer.initVerify(pk);
+        } else {
+            signer.initVerify(cert);
+        }
+
+        calculateSignature(exchange, signer);
+
+        byte[] signature = getSignatureFromExchange(exchange);
+        if (!signer.verify(signature)) {
+            throw new SignatureException("Cannot verify signature of exchange");
+        }
+        clearMessageHeaders(exchange.getIn());
+    }
+
+    private byte[] getSignatureFromExchange(Exchange exchange) throws Exception {
+        String encodedSignature = ExchangeHelper.getMandatoryHeader(exchange, config.getSignatureHeader(), String.class);
+        if (encodedSignature == null) {
+            throw new IllegalStateException("Cannot verify exchange as no " + config.getSignatureHeader() + " header is present.");
+        }
+        return new Base64().decode(encodedSignature);
+    }
+
+    private Certificate getCertificate(Exchange exchange) throws Exception {
+        Certificate cert = config.getCertificate(getAlias(exchange));
+        return getPublicKeyOrCertificateFromHeader(exchange, Certificate.class, cert);
+    }
+
+    private <T> T getPublicKeyOrCertificateFromHeader(Exchange exchange, Class<? extends T> verificationType, T defaultsTo) {
+        T pkOrCert = exchange.getIn().getHeader(SIGNATURE_PUBLIC_KEY_OR_CERT, verificationType);
+        if (pkOrCert == null) {
+            pkOrCert = defaultsTo;
+        }
+        return pkOrCert;
+    }
+
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/processor/VerifyingProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java?rev=926499&view=auto
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java (added)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java Tue Mar 23 08:49:46 2010
@@ -0,0 +1,303 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.converter.crypto;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Key;
+import java.security.spec.AlgorithmParameterSpec;
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
+import javax.crypto.spec.IvParameterSpec;
+
+import static javax.crypto.Cipher.DECRYPT_MODE;
+import static javax.crypto.Cipher.ENCRYPT_MODE;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <code>CryptoDataFormat</code> 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
+ * <ul>
+ * <li>http://en.wikipedia.org/wiki/Initialization_vector</li>
+ * <li>http://www.herongyang.com/Cryptography/</li>
+ * <li>http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation</li>
+ * <ul>
+ * <p/>
+ * To avoid attacks against the encrypted data while it is in transit the
+ * {@link 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
+ * <ul>
+ * <li>http://en.wikipedia.org/wiki/HMAC</li>
+ * </ul>
+ */
+public class CryptoDataFormat implements DataFormat {
+
+    public static final String KEY = "CamelCryptoKey";
+
+    private static final Log LOG = LogFactory.getLog(CryptoDataFormat.class);
+    private static final String INIT_VECTOR = "CamelCryptoInitVector";
+    private String algorithm = "DES/CBC/PKCS5Padding";
+    private String cryptoProvider;
+    private Key configuredkey;
+    private int bufferSize = 4096;
+    private byte[] initializationVector;
+    private boolean inline;
+    private String macAlgorithm = "HmacSHA1";
+    private boolean shouldAppendHMAC;
+    private AlgorithmParameterSpec parameterSpec;
+
+    public CryptoDataFormat() {
+    }
+
+    public CryptoDataFormat(String algorithm, Key key) {
+        this(algorithm, key, null);
+    }
+
+    public CryptoDataFormat(String algorithm, Key key, String cryptoProvider) {
+        this.algorithm = algorithm;
+        this.configuredkey = key;
+        this.cryptoProvider = cryptoProvider;
+    }
+
+    private Cipher initializeCipher(int mode, Key key, byte[] iv) throws Exception {
+        Cipher cipher = cryptoProvider == null ? Cipher.getInstance(algorithm) : Cipher.getInstance(algorithm, cryptoProvider);
+
+        if (key == null) {
+            throw new IllegalStateException("A valid encryption key is required. Either configure the CryptoDataFormat "
+                    + "with a key or provide one in a header using the header name 'CamelCryptoKey'");
+        }
+
+        if (mode == ENCRYPT_MODE || mode == DECRYPT_MODE) {
+            if (iv != null) {
+                cipher.init(mode, key, new IvParameterSpec(iv));
+            } else if (parameterSpec != null) {
+                cipher.init(mode, key, parameterSpec);
+            } else {
+                cipher.init(mode, key);
+            }
+        }
+        return cipher;
+    }
+
+    public void marshal(Exchange exchange, Object graph, OutputStream outputStream) throws Exception {
+        byte[] iv = getInitializationVector(exchange);
+        Key key = getKey(exchange);
+
+        CipherOutputStream cipherStream = new CipherOutputStream(outputStream, initializeCipher(ENCRYPT_MODE, key, iv));
+        InputStream plaintextStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
+        HMACAccumulator hmac = getMessageAuthenticationCode(key);
+        if (plaintextStream != null) {
+            inlineInitVector(outputStream, iv);
+            byte[] buffer = new byte[bufferSize];
+            int read;
+            try {
+                while ((read = plaintextStream.read(buffer)) > 0) {
+                    cipherStream.write(buffer, 0, read);
+                    cipherStream.flush();
+                    hmac.encryptUpdate(buffer, read);
+                }
+                cipherStream.write(hmac.getCalculatedMac());
+            } finally {
+                ObjectHelper.close(cipherStream, "cipher", LOG);
+            }
+        }
+    }
+
+    public Object unmarshal(Exchange exchange, InputStream encryptedStream) throws Exception {
+        Object unmarshalled = null;
+        if (encryptedStream != null) {
+            byte[] iv = getInlinedInitializationVector(exchange, encryptedStream);
+            Key key = getKey(exchange);
+            CipherInputStream cipherStream = new CipherInputStream(encryptedStream, initializeCipher(DECRYPT_MODE, key, iv));
+
+            ByteArrayOutputStream plaintextStream = new ByteArrayOutputStream(bufferSize);
+            HMACAccumulator hmac = getMessageAuthenticationCode(key);
+            byte[] buffer = new byte[bufferSize];
+            hmac.attachStream(plaintextStream);
+            int read;
+            while ((read = cipherStream.read(buffer)) >= 0) {
+                hmac.decryptUpdate(buffer, read);
+            }
+            hmac.validate();
+            unmarshalled = plaintextStream.toByteArray();
+        }
+        return unmarshalled;
+    }
+
+    private void inlineInitVector(OutputStream outputStream, byte[] iv) throws IOException {
+        if (inline) {
+            DataOutputStream dout = new DataOutputStream(outputStream);
+            dout.writeInt(iv.length);
+            outputStream.write(iv);
+            outputStream.flush();
+        }
+    }
+
+    private byte[] getInlinedInitializationVector(Exchange exchange, InputStream encryptedStream) throws IOException {
+        byte[] iv = getInitializationVector(exchange);
+        if (inline) {
+            try {
+                int ivLength = new DataInputStream(encryptedStream).readInt();
+                iv = new byte[ivLength];
+                int read = encryptedStream.read(iv);
+                if (read != ivLength) {
+                    throw new IOException(String.format("Attempted to read a '%d' byte initialization vector from inputStream but only"
+                            + " '%d' bytes were retrieved", ivLength, read));
+                }
+            } catch (IOException e) {
+                throw IOHelper.createIOException("Error Reading Initialization vector from encrypted stream", e);
+            }
+        }
+        return iv;
+    }
+
+    private HMACAccumulator getMessageAuthenticationCode(Key key) throws Exception {
+        // return an actual Hmac Calculator or a 'Null' noop version.
+        return shouldAppendHMAC ? new HMACAccumulator(key, macAlgorithm, cryptoProvider, bufferSize) : new HMACAccumulator() {
+            byte[] empty = new byte[0];
+
+            public void encryptUpdate(byte[] buffer, int read) {
+            }
+
+            public void decryptUpdate(byte[] buffer, int read) throws IOException {
+                outputStream.write(buffer, 0, read);
+            }
+
+            public void validate() {
+            }
+
+            public byte[] getCalculatedMac() {
+                return empty;
+            }
+        };
+    }
+
+    private byte[] getInitializationVector(Exchange exchange) {
+        byte[] iv = exchange.getIn().getHeader(INIT_VECTOR, byte[].class);
+        if (iv == null) {
+            iv = initializationVector;
+        }
+        return iv;
+    }
+
+    private Key getKey(Exchange exchange) {
+        Key key = exchange.getIn().getHeader(KEY, Key.class);
+        if (key != null) {
+            exchange.getIn().setHeader(KEY, null);
+        } else {
+            key = configuredkey;
+        }
+        return key;
+    }
+
+    public void setInitializationVector(byte[] initializationVector) {
+        if (initializationVector != null) {
+            this.initializationVector = initializationVector;
+        }
+    }
+
+    /**
+     * 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. When the payload is to be decrypted this
+     * initialization vector will need to be read from the stream. Requires that
+     * the formatter has been configured with an init vector that is valid for
+     * the give algorithm.
+     *
+     * @param inline true if the initialization vector should be inlined in the stream.
+     */
+    public void setShouldInlineInitializationVector(boolean inline) {
+        this.inline = inline;
+    }
+
+    /**
+     * Sets the JCE name of the Encryption Algorithm that should be used
+     */
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+
+    /**
+     * Sets a custom {@link 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
+     * ignored
+     */
+    public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) {
+        this.parameterSpec = parameterSpec;
+    }
+
+    /**
+     * Sets the name of the JCE provider e.g. SUN or BC for Bouncy
+     */
+    public void setCryptoProvider(String cryptoProvider) {
+        this.cryptoProvider = cryptoProvider;
+    }
+
+    /**
+     * Sets the algorithm used to create the Hash-based Message Authentication
+     * Code (HMAC) appended to the stream.
+     */
+    public void setMacAlgorithm(String macAlgorithm) {
+        this.macAlgorithm = macAlgorithm;
+    }
+
+    /**
+     * Whether a Hash-based Message Authentication Code (HMAC) should be
+     * calculated and appended to the stream.
+     */
+    public void setShouldAppendHMAC(boolean shouldAppendHMAC) {
+        this.shouldAppendHMAC = shouldAppendHMAC;
+    }
+
+    /**
+     * Set the key that should be used to encrypt or decrypt incoming encrypted exchanges.
+     */
+    public void setKey(Key key) {
+        this.configuredkey = key;
+    }
+
+    /**
+     * Set the size of the buffer used to
+     */
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
+    }
+}

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date