76.7. キーを動的に提供する

受信者リストまたは同様の EIP を使用する場合、エクスチェンジの受信者は動的に変化する可能性があります。すべての受信者に同じキーを使用することは、実現可能または望ましくない場合があります。エクスチェンジごとにキーを動的に指定できると便利です。エクスチェンジは、データ形式によって処理される前に、ターゲット受信者のキーで動的に強化される可能性があります。これを容易にするために、DataFormat は以下のメッセージヘッダーを介してキーを動的に提供できるようにします。

  • CryptoDataFormat.KEY "CamelCryptoKey"
CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", null);
/**
 * 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("direct:key-in-header-encrypt")
    .marshal(cryptoFormat)
    .removeHeader(CryptoDataFormat.KEY)
    .to("mock:encrypted");

from("direct:key-in-header-decrypt").unmarshal(cryptoFormat).process(new Processor() {
    public void process(Exchange exchange) throws Exception {
        exchange.getIn().getHeaders().remove(CryptoDataFormat.KEY);
        exchange.getOut().copyFrom(exchange.getIn());
    }
}).to("mock:unencrypted");

または Spring 付き。

<crypto id="nokey" algorithm="DES" />