75.7. 동적으로 키 제공
Recipient 목록 또는 유사한 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");또는 봄과 함께.
<crypto id="nokey" algorithm="DES" />