public static string CalculateSHA1(string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
string hash = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
return hash;
}
谢谢!
VStudio一直对我大吼大叫,因为我到目前为止最特别是Byte末尾的括号?:
Private Sub CalculateSHA1(ByVal text As String, ByVal enc As Encoding)
Dim buffer As Byte[] = enc.GetBytes(text);
End Sub
答案 0 :(得分:8)
这个怎么样?
Public Shared Function CalculateSHA1(text As String, enc As Encoding) As String
Dim buffer As Byte() = enc.GetBytes(text)
Dim cryptoTransformSHA1 As New SHA1CryptoServiceProvider()
Dim hash As String = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "")
Return hash
End Function
VB.NET不对数组使用[]
,而是使用()
代替。
答案 1 :(得分:2)
除了安德鲁的回答,还有quite a few simple converter tools on the web.我倾向于use this one with good success when needed.
答案 2 :(得分:0)
你试过吗
Dim buffer as Byte() = enc.GetBytes(text)
没有分号?
答案 3 :(得分:0)
Public Shared Function CalculateSHA1(ByVal text As String, ByVal enc As Encoding) As String
Dim buffer As Byte() = enc.GetBytes(text)
Dim cryptoTransformSHA1 As New SHA1CryptoServiceProvider()
Dim hash As String = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "")
Return hash
End Function
答案 4 :(得分:0)
尝试将括号更改为括号:
Dim buffer As Byte() = enc.GetBytes(text);