java版hmac-md5 with hex

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




新博客地址

猜你喜欢

转载自alexzh.iteye.com/blog/1666870
hex
今日推荐