欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java版hmac-md5 with hex

程序员文章站 2022-06-07 21:20:44
...
java hmac-md5

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Hex;

public class EncodeTest {

public static void main(String[] args) throws Exception {
    SecretKey key = new SecretKeySpec("secretkey".getBytes(), "HmacMD5");
    Mac mac = Mac.getInstance(key.getAlgorithm());
    mac.init(key);
    byte[] code = mac.doFinal("the message need sign".getBytes());
    System.out.println(Hex.encodeHex(code));
    }
}




新博客地址