vbnet Hash

Private Function GenerateHash(ByVal Data As String, ByVal Type As String) As String
	'from: http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx
	'and: http://www.stardeveloper.com/articles/display.html?article=2003062001&page=1
	Dim HashData As Byte()
	Dim result() As Byte
	Dim resultHexString As String = ""
	Dim b As Byte

	HashData = Encoding.ASCII.GetBytes(Data)

	Select Case Type
		Case "SHA-1"
			Dim sha As New System.Security.Cryptography.SHA1CryptoServiceProvider()
			result = sha.ComputeHash(HashData)
		Case "SHA-256"
			Dim sha As New System.Security.Cryptography.SHA256CryptoServiceProvider()
			result = sha.ComputeHash(HashData)
		Case "SHA-512"
			Dim sha As New System.Security.Cryptography.SHA512CryptoServiceProvider()
			result = sha.ComputeHash(HashData)
		Case "MD5"
			Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider()
			result = md5.ComputeHash(HashData)
		Case ""
		Case Else
			Return ""
			Exit Function
	End Select

	For Each b In result
		resultHexString += Hex(b)
	Next

	Return resultHexString
End Function
Creates various Hashes of Strings, depending on the Type. This can be seen in action at beta.slickhouse.com

Updated: Thursday 7th October 2010, 10:42pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.