### camel-crypto

Secure message exchanges in camel is provided by the http://camel.apache.org/crypto-digital-signatures.html[crypto,window=_blank] component.

With Camel cryptographic endpoints and Java's Cryptographic extension it is easy to create Digital Signatures for Exchanges. Camel provides a pair of flexible endpoints which get used in concert to create a signature for an exchange in one part of the exchange's workflow and then verify the signature in a later part of the workflow.

Begin by loading a keystore for binding to JNDI so that camel can discover it from its bean registry.

[source,java,options="nowrap"]
----
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream in = getClass().getResourceAsStream("/my-keystore.ks");
keystore.load(in, "my-keystore-password".toCharArray());

Certificate cert = keystore.getCertificate("my-certificate-alias");

KeyStoreParameters keystoreParameters = new KeyStoreParameters();
keystoreParameters.setPassword("my-keystore-password");
keystoreParameters.setResource("./my-keystore.ks");

InitialContext initialContext = new InitialContext();
initialContext.bind("signatureParams", keystoreParameters);
initialContext.bind("keystore", keystore);
initialContext.bind("myPublicKey", cert.getPublicKey());
initialContext.bind("myCert", cert);
initialContext.bind("myPrivateKey", keystore.getKey("my-certificate-alias", "my-keystore-password".toCharArray()));
----

Finally, a Camel route that signs and verifies an exchange.

[source,java,options="nowrap"]
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
      from("direct:sign")
      .to("crypto:sign://basic?privateKey=#myPrivateKey")
      .to("direct:verify");

      from("direct:verify")
      .to("crypto:verify://basic?publicKey=#myPublicKey")
      .to("mock:result");
    }
});

