0

我有一段 C# 代码,我正在尝试用 java 重写它。

但是我的 Java 代码没有得到预期的结果。我究竟做错了什么?

C#代码:

string response = pwd + challenge;
System.Security.Cryptography.SHA1CryptoServiceProvider SHA1 = 
   new System.Security.Cryptography.SHA1CryptoServiceProvider(); 
SHA1.Initialize();
byte[] hash = SHA1.ComputeHash(System.Text.Encoding.Default.GetBytes(response));
System.Text.StringBuilder builder = new System.Text.StringBuilder(); 
foreach (byte b in hash)
    builder.Append(b.ToString("x2"));

Java代码:

MessageDigest messageDigest  = MessageDigest.getInstance("SHA-1");
    byte[] digest = messageDigest.digest((PASSWORD + challenge).getBytes());

    String result = new BigInteger(1, digest).toString(16);
4

0 回答 0