75.4. 指定加密算法

更改算法是提供 JCE 算法名称的关键。如果您更改了使用兼容密钥的算法。

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");

Java 7 中可用算法列表可以通过 Java Cryptography Architecture Standard Algorithm Name 文档获得。