Showing posts with label SHA1 algorithm. Show all posts
Showing posts with label SHA1 algorithm. Show all posts

Oct 6, 2010

Using SHA1 algorithm

The following code demonstrates using SHA1 algorithm to hash a password:

In VB:


Imports System.Security.Cryptography 
Public Function ComputeSHA1(ByVal textToHash As String) As String 
    Dim SHA1 As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider 
    Dim byteV As Byte() = System.Text.Encoding.UTF8.GetBytes(textToHash) 
    Dim byteH As Byte() = SHA1.ComputeHash(byteV) 
    SHA1.Clear() 
    Return Convert.ToBase64String(byteH) 
End Function 


In C#:

using System.Security.Cryptography; 
public static String ComputeSHA1(string textToHash) 
{ 
    SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider(); 
    byte[] byteV = System.Text.Encoding.UTF8.GetBytes(textToHash); 
    byte[] byteH = SHA1.ComputeHash(byteV); 
    SHA1.Clear(); 
    return Convert.ToBase64String(byteH); 
}