Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

cryptography - How to Generate HMAC MD5 In Android?

I am new in this Field!I have this Message and Key also i want HMAC MD5 using this two so how it is possible if possible then give some example or sample code of this.The Given link display the overall functionality i want such kind of code.Please help me.

Messgae = POSTuserMon,28Jun201010:18:33GMT7FF4471B-13C0-5A9F-BB7B-7309F1AB7F08

key = d6fc3a4a06ed55d24fecde188aaa9161

Link = http://hash.online-convert.com/md5-generator

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are working codes.
Generated result is same as Link = http://hash.online-convert.com/md5-generator

public String calcHmac(String src) throws Exception {

    String key = "d6fc3a4a06ed55d24fecde188aaa9161";
    Mac mac = Mac.getInstance("HmacSHA1");
    SecretKeySpec sk = new SecretKeySpec(key.getBytes(),mac.getAlgorithm());  
    mac.init(sk);
    byte[] result = mac.doFinal(src.getBytes());


    return Base64.encodeToString(result ,Base64.URL_SAFE);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...