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


Top 5 Contributors of the Month
david stephan

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


     

Further Readings:

Responses

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