75.6. 해시된 메시지 인증 코드(HMAC)

CryptoDataFormat을 전송하는 동안 암호화된 데이터에 대한 공격을 방지하려면 구성 가능한 MAC 알고리즘을 기반으로 암호화된 교환 콘텐츠에 대한 메시지 인증 코드를 계산할 수도 있습니다. 계산된 HMAC는 암호화 후 스트림에 추가됩니다. 암호 해독 단계의 스트림과 분리됩니다. 전송 중 아무것도 변경되지 않도록 전송된 버전에 대해 MAC을 다시 계산 및 확인합니다. 메시지 인증 코드에 대한 자세한 내용은 http://en.wikipedia.org/wiki/HMAC을 참조하십시오.

KeyGenerator generator = KeyGenerator.getInstance("DES");

CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
cryptoFormat.setShouldAppendHMAC(true);

from("direct:hmac")
    .marshal(cryptoFormat)
    .to("mock:encrypted")
    .unmarshal(cryptoFormat)
    .to("mock:unencrypted");

또는 봄과 함께.

<crypto id="hmac" algorithm="DES" keyRef="desKey" shouldAppendHMAC="true" />

기본적으로 HMAC는 HmacSHA1 mac 알고리즘을 사용하여 계산되지만 다른 알고리즘 이름을 제공하여 쉽게 변경할 수 있습니다. 구성된 보안 공급자를 통해 사용 가능한 알고리즘을 확인하는 방법은 여기를 참조하십시오.

KeyGenerator generator = KeyGenerator.getInstance("DES");

CryptoDataFormat cryptoFormat = new CryptoDataFormat("DES", generator.generateKey());
cryptoFormat.setShouldAppendHMAC(true);
cryptoFormat.setMacAlgorithm("HmacMD5");

from("direct:hmac-algorithm")
    .marshal(cryptoFormat)
    .to("mock:encrypted")
    .unmarshal(cryptoFormat)
    .to("mock:unencrypted");

또는 봄과 함께.

<crypto id="hmac-algorithm" algorithm="DES" keyRef="desKey" macAlgorithm="HmacMD5" shouldAppendHMAC="true" />