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.