解决java,C#,php,python MD5加密不一致问题

JAVA写法

 public static String md5Base64(final String str, final String key) throws Exception {
        if ((null == str) || "".equals(str)) {
            return "";
        }

        MessageDigest messagedigest;

        messagedigest = MessageDigest.getInstance("MD5");

        String data = str;

        if ((null != key) && !"".equals(key)) {
            data += key;
        }

        messagedigest.update(data.getBytes("UTF-8"));

        byte[] baseStr = Base64.encodeBase64(messagedigest.digest());

        return new String(baseStr);
    }

 

C#写法

        public static string Md5tobase64(string logistics_interface)
        {
            MD5CryptoServiceProvider D = new MD5CryptoServiceProvider();
            string str1 = logistics_interface;
            byte[] result = D.ComputeHash(System.Text.UnicodeEncoding.GetEncoding("UTF-8").GetBytes(str1));

            return Convert.ToBase64String(result);
        }

 

php写法

 base64_encode(hex2bin(md5($send_data .$send_key )))

python写法 

# 签名MD5+base64
def get_data_digest(params):
m = hashlib.md5()
m.update(params.encode("utf8"))
data_digest = m.digest()
data_digest = base64.b64encode(data_digest).decode()
return data_digest

 

你可能感兴趣的:(解决java,C#,php,python MD5加密不一致问题)