PHP MD5不匹配VB.净MD5


PHP MD5 Not Matching VB.NET MD5

我试图在PHP和VB中获得相同的MD5哈希值。. NET但无论我使用什么文本编码,我都无法获得哈希匹配。我做错了什么?下面是我用每种语言编写的代码:

PHP代码:

echo '<b>$20.00 (UTF-32)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-32'));  
echo '<b>$20.00 (UTF-32LE)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-32LE'));
echo '<b>$20.00 (UTF-32BE)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-32BE'));
echo '<b>$20.00 (UTF-8)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-8'));
echo '<b>$20.00 (UTF-7)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-7'));
echo '<b>$20.00 (UTF-16)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-16'));
echo '<b>$20.00 (UTF-16LE)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-16LE'));
echo '<b>$20.00 (UTF-16BE)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'UTF-16BE'));
echo '<b>$20.00 (ASCII)</b> = ' . md5(mb_convert_encoding('1C9BRPS3TN85I2ULE5FP' + '20.00', 'ASCII'));

VB。NET代码:

Try
' Create a new instance of the MD5 object.
Dim md5Hasher As MD5 = MD5.Create()
' Convert the input string to a byte array and compute the hash.
Dim strInput As String = "1C9BRPS3TN85I2ULE5FP" & "20.00"
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.UTF32.GetBytes(strInput))
' Create a new Stringbuilder to collect the bytes
' and create a string.
Dim sBuilder As New StringBuilder()
' Loop through each byte of the hashed data 
' and format each one as a hexadecimal string.
Dim i As Integer
For i = 0 To data.Length - 1
    sBuilder.AppendFormat("{0:x2}", data(i))
    'sBuilder.Append(data(i).ToString("x2"))
Next i
lblResponse.Text = "<b>$20.00 (UTF-32)</b> = " & sBuilder.ToString() & "<br>"
' Try a different encoding
data = md5Hasher.ComputeHash(Encoding.ASCII.GetBytes(strInput))
' Loop through each byte of the hashed data 
' and format each one as a hexadecimal string.
sBuilder.Length = 0
For i = 0 To data.Length - 1
    sBuilder.AppendFormat("{0:x2}", data(i))
Next i
lblResponse.Text &= "<b>$20.00 (ASCII)</b> = " & sBuilder.ToString() & "<br>"
' Try a different encoding
data = md5Hasher.ComputeHash(Encoding.Unicode.GetBytes(strInput))
' Loop through each byte of the hashed data 
' and format each one as a hexadecimal string.
sBuilder.Length = 0
For i = 0 To data.Length - 1
    sBuilder.AppendFormat("{0:x2}", data(i))
Next i
lblResponse.Text &= "<b>$20.00 (Unicode)</b> = " & sBuilder.ToString() & "<br>"
' Try a different encoding
data = md5Hasher.ComputeHash(Encoding.UTF7.GetBytes(strInput))
' Loop through each byte of the hashed data 
' and format each one as a hexadecimal string.
sBuilder.Length = 0
For i = 0 To data.Length - 1
    sBuilder.AppendFormat("{0:x2}", data(i))
Next i
lblResponse.Text &= "<b>$20.00 (UTF7)</b> = " & sBuilder.ToString() & "<br>"
' Try a different encoding
data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(strInput))
' Loop through each byte of the hashed data 
' and format each one as a hexadecimal string.
sBuilder.Length = 0
For i = 0 To data.Length - 1
    sBuilder.AppendFormat("{0:x2}", data(i))
Next i
lblResponse.Text &= "<b>$20.00 (UTF8)</b> = " & sBuilder.ToString() & "<br>"
Catch ex As Exception
    lblErrorMessage.Text = ex.ToString()
End Try

PHP中的字符串连接是.,而不是VB.Net中的+。因此,'1C9BRPS3TN85I2ULE5FP' + '20.00'不会在PHP中产生'1C9BRPS3TN85I2ULE5FP20.00'

Edit: VB.net的Real字符串连接是&,但由于使用了术语visual basic+符号可以做同样的事情,只要数学解释是无意义的。所以为了安全起见,请使用&