C# – Can someone convert this Hashing method from C# to VB


  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 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

Best Solution

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.

Related Question