C#MD5哈希与Java / PHP MD5哈希不匹配

Mrvnagstn

我的练习是将administration-backendphp从php移植到.net。

后端与用Java编写的应用程序进行通信。

与md5-哈希相比,有些东西在php和java中md5哈希是同等的。

我无法在Java应用程序中更改md5哈希码,因为这样一来,超过1万张客户卡将无法使用。

我的问题是,后端已移植,现在新的后端(.net)与Java应用程序之间进行了通信。

我的.net md5-hash代码返回的哈希值与Java代码不同。

Java的:

    public static String getMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");

            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);


            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32)
                hashtext = "0" + hashtext;
            return hashtext;
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

和我的.net代码:

        public String hashMD5(String wert)
    {


        byte[] asciiBytes = ASCIIEncoding.UTF8.GetBytes(wert);
        byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
        string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();

        return hashedString;
    }

我的Java代码返回了bb27aee4

46d5acfcd281bca9f1df7c9e38d50576

我的.net代码返回:

b767fe33172ec6cbea569810ee6cfc05

我不知道该怎么办...

请帮助并提前致谢。

KiKMak

它不是MD5哈希生成器的问题

的MD5哈希bb27aee446d5acfcd281bca9f1df7c9e38d50576和的
MD5哈希BB27AEE4b767fe33172ec6cbea569810ee6cfc05

因此,基本上在.NET中,您正在为其生成MD5哈希,BB27AEE4而不是bb27aee4

因此,请检查代码中的错误

祝你好运

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章