Reputation: 43813
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;
}
THANKS!
VStudio keeps yelling at me for just what I have so far most specifically the bracket at the end of Byte?:
Private Sub CalculateSHA1(ByVal text As String, ByVal enc As Encoding)
Dim buffer As Byte[] = enc.GetBytes(text);
End Sub
Upvotes: 0
Views: 406
Reputation: 21
Try changing the brackets to parentheses:
Dim buffer As Byte() = enc.GetBytes(text);
Upvotes: 0
Reputation: 9344
In addition to Andrew's answer, there are quite a few simple converter tools on the web. I tend to use this one with good success when needed.
Upvotes: 2
Reputation: 8263
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
Upvotes: 0
Reputation: 1865
Did you try
Dim buffer as Byte() = enc.GetBytes(text)
no semicolon?
Upvotes: 0
Reputation: 351456
How about this?
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 doesn't use []
for arrays, it uses ()
instead.
Upvotes: 8