这是 SHA1 变体的解决方案。
public static string GetSwcSHA1(string value)
{
SHA1 algorithm = SHA1.Create();
byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
string sh1 = "";
for (int i = 0; i < data.Length; i++)
{
sh1 += data[i].ToString("x2").ToUpperInvariant();
}
return sh1;
}
对于 MD5,您只需将算法更改为:
MD5 algorithm = MD5.Create();
希望您不介意,只需在上面添加代码的 VB.NET 变体:
Public Shared Function CreateHash(saltAndPassword) As String
Dim Algorithm As SHA1 = SHA1.Create()
Dim Data As Byte() = Algorithm.ComputeHash(Encoding.UTF8.GetBytes(saltAndPassword))
Dim Hashed As String = ""
For i As Integer = 0 To Data.Length - 1
Hashed &= Data(i).ToString("x2").ToUpperInvariant()
Next
Return Hashed
End Function