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




新博客地址

你可能感兴趣的:(java版hmac-md5 with hex)