admin
2024-07-03 a40e0e51331e5e6f69e8bed5940512b29150c7a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.taoke.autopay.android.utils;
 
import android.annotation.SuppressLint;
import android.util.Log;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
public class MD5Utils {
 
    private static final String TAG = "MD5Util";
 
    @SuppressLint("LogNotTimber")
    public static String getMD532(String key) {
        String cacheKey = "";
        try {
            final MessageDigest mDigest = MessageDigest.getInstance("MD5");
            mDigest.update(key.getBytes());
            cacheKey = bytesToHexString(mDigest.digest());
        } catch (NoSuchAlgorithmException e) {
            Log.e(TAG, e.getMessage());
        }
        return cacheKey;
    }
 
    private static String bytesToHexString(byte[] bytes) {
        // http://stackoverflow.com/questions/332079
        StringBuilder sb = new StringBuilder();
        for (byte aByte : bytes) {
            String hex = Integer.toHexString(0xFF & aByte);
            if (hex.length() == 1) {
                sb.append('0');
            }
            sb.append(hex);
        }
        return sb.toString();
    }
}