public static void jdkHmacMD5() { try { // 初始化KeyGenerator KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacMD5"); // 产生密钥 SecretKey secretKey = keyGenerator.generateKey(); // 获取密钥 byte[] key = secretKey.getEncoded(); // byte[] key = Hex.decodeHex(new char[]{'1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e'}); // 还原密钥 SecretKey restoreSecretKey = new SecretKeySpec(key, "HmacMD5"); // 实例化MAC Mac mac = Mac.getInstance(restoreSecretKey.getAlgorithm()); // 初始化MAC mac.init(restoreSecretKey); // 执行摘要 byte[] hmacMD5Bytes = mac.doFinal("data".getBytes()); System.out.println("jdk hmacMD5:" + new String(hmacMD5Bytes)); } catch (Exception e) { e.printStackTrace(); } }
详细分析JAVA加解密算法(6)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/c1178b5624d9039f0d98a86ac0af3a8a.html