How to Generate HMAC MD5 In Android?

前端 未结 2 1982
无人及你
无人及你 2020-12-16 08:59

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 Gi

2条回答
  •  佛祖请我去吃肉
    2020-12-16 09:45

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

提交回复
热议问题