package com.zit;
import java.security.NoSuchAlgorithmException;
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
import com.sun.crypto.provider.HmacMD5;
public class HmacTest {
private static String src = "hello hmac";
public static void main(String[] args) {
jdkHmacMD5();
}
public static void jdkHmacMD5() {
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD5");// 初始化KeyGenerator
SecretKey secretKey = keyGenerator.generateKey();// 产生秘钥
byte[] key = secretKey.getEncoded();// 获得秘钥(默认生成)
// byte[]key=Hex.decodeHex(new
// char[]{'a','a','a','a','a','a','a','a','a','a'});//手动生成秘钥(十位)
SecretKey secretKey2 = new SecretKeySpec(key, "HmacMD5");// 还原秘钥
hMac加密
最新推荐文章于 2024-07-13 09:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)