View Single Post
  #4 (permalink)  
Old 02-08-2008, 04:50 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Post Re: Using the Cryptography APIs in .NET

To test the subroutine, simply call the Hashing_SHA1() subroutine in Main():

Code:
Sub Main()
        Hashing_SHA1()
        Console.Read()
    End Sub
You can also use the MD5 implementation to perform hashing, as the following subroutine shows:

Code:
 Private Sub Hashing_MD5()
        '---ask the user to enter a password---
        Console.Write("Please enter a password: ")
        Dim password As String = Console.ReadLine()

        '---hash the password---
        Dim data() As Byte = ASCII.GetBytes(password)
        Dim passwordHash() As Byte
        Dim md5 As New MD5CryptoServiceProvider()
        passwordHash = md5.ComputeHash(data)

        '---ask the user to enter the same password again---
        Console.Write("Please enter password again: ")
        password = Console.ReadLine()

        '---hash the second password and compare it with the first---
        data = ASCII.GetBytes(password)
        If ASCII.GetString(passwordHash) = _
           ASCII.GetString(md5.ComputeHash(data)) Then
            Console.WriteLine("Same password")
        Else
            Console.WriteLine("Incorrect password")
        End If
    End Sub
The main difference is that the hash value for MD5 is 128 bits in length.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Reply With Quote