Using SHA1 algorithm


The following code demonstrates using SHA1 algorithm to hash a password

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);
}


Comments

Author: Arivazhagan Sekar05 Oct 2010 Member Level: Gold   Points : 0

Thanks friend, its a good post and it is very useful for me...

Author: Arivazhagan Sekar05 Oct 2010 Member Level: Gold   Points : 1

hi friend, shall i get the Hast value back to text?
i any possibility to get the Original Text from a hashed value?

Author: Arivazhagan Sekar05 Oct 2010 Member Level: Gold   Points : 0

Thanks friend, its a good post and it is very useful for me...



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: