tags:

views:

165

answers:

5
  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
+8  A: 

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.

Andrew Hare
A: 

Did you try

Dim buffer as Byte() = enc.GetBytes(text)

no semicolon?

swolff1978
A: 
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
Quinn Wilson
+2  A: 

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.

Marc
A: 

Try changing the brackets to parentheses:

Dim buffer As Byte() = enc.GetBytes(text);
JHBlues76