.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani

Home >> Code Snippets >> Security >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using SHA1 algorithm

Posted By:Deepika Haridas       Posted Date: October 13, 2010    Points: 15    Category: Security    URL: http://www.dotnetspark.com  

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) 
    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); 
    return Convert.ToBase64String(byteH); 


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Related Resource From The Same Category

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend