73.2. 基本的な使用方法
交換の暗号化/復号化に必要となる最も基本的なものはすべて、共有秘密キーです。Crypto データフォーマットの 1 つ以上のインスタンスがこのキーで設定されている場合、フォーマットを使用してあるルート(または一部)でペイロードを暗号化し、別のルートで復号化できます。たとえば、以下のように Java DSL を使用します。
KeyGenerator generator = KeyGenerator.getInstance("DES"); CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey()); from("direct:basic-encryption") .marshal(cryptoFormat) .to("mock:encrypted") .unmarshal(cryptoFormat) .to("mock:unencrypted");
KeyGenerator generator = KeyGenerator.getInstance("DES");
CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
from("direct:basic-encryption")
.marshal(cryptoFormat)
.to("mock:encrypted")
.unmarshal(cryptoFormat)
.to("mock:unencrypted");
Spring では、最初に dataformat を設定し、ルートで使用されます。
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <dataFormats> <crypto id="basic" algorithm="DES" keyRef="desKey" /> </dataFormats> ... <route> <from uri="direct:basic-encryption" /> <marshal ref="basic" /> <to uri="mock:encrypted" /> <unmarshal ref="basic" /> <to uri="mock:unencrypted" /> </route> </camelContext>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<crypto id="basic" algorithm="DES" keyRef="desKey" />
</dataFormats>
...
<route>
<from uri="direct:basic-encryption" />
<marshal ref="basic" />
<to uri="mock:encrypted" />
<unmarshal ref="basic" />
<to uri="mock:unencrypted" />
</route>
</camelContext>