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");
또는 봄과 함께.
<crypto id="nokey" algorithm="DES" />