73.5. ハッシュされたメッセージ認証コード(HMAC)
CryptoDataFormat の移動中に暗号化されたデータに対する攻撃を回避するために、設定可能な MAC アルゴリズムに基づいて、暗号化されたエクスチェンジコンテンツ用の Message Authentication Code を算出することもできます。計算された 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");
または spring で行います。
<crypto id="hmac" algorithm="DES" keyRef="desKey" shouldAppendHMAC="true" />
デフォルトでは、HmacSHA1 mac アルゴリズムを使用して HMAC が計算されますが、別のアルゴリズム名を指定することで簡単に変更できます。設定したセキュリティープロバイダーから利用可能なアルゴリズムを確認する方法については、こちらを参照してください。
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");
または spring で行います。
<crypto id="hmac-algorithm" algorithm="DES" keyRef="desKey" macAlgorithm="HmacMD5" shouldAppendHMAC="true" />