Youve often seen these long, seemingly random numbers in secured web pages and perhaps wondered just what the heck that is meant to be. Well, usually these long numbers are hash codes, a system used to perform one-way data authentication. The MD5 hash algorithm is one of the most commonly used hashing functions, mainly because of its ease of implementation and the fact that it is a fairly secure one direction hash (In fact, this is basically how Windows authenticates its passwords). –
Creating hash codes in VB6 was quite a mission, possible, but a mission. Then came along VB.NET to make things a little easier, providing a fairly decent set of classes under its System.Security.Cryptography namespace.
As an example, below is a generic function that returns an MD5 hash, formatted as a String, from the contents of a string you pass into the function.
Imports System.Text
Imports System.Security.Cryptography
Private Function GenerateHash(ByVal SourceText As String) As String
‘Create an encoding object to ensure the encoding standard for the source text
Dim Ue As New UnicodeEncoding()
‘Retrieve a byte array based on the source text
Dim ByteSourceText() As Byte = Ue.GetBytes(SourceText)
‘Instantiate an MD5 Provider object
Dim Md5 As New MD5CryptoServiceProvider()
‘Compute the hash value from the source
Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
‘And convert it to String format for return
Return Convert.ToBase64String(ByteHash)
End Function
Related link: http://www.a1vbcode.com/vbtip-149.asp
You might also enjoy:
-
If you come from a VB programming background, often you are left floundering when trying to retrieve character codes from a string or vice versa, trying to ...
-
Two more quick and dirty applications that I needed can now be found under the CodeUnit banner.MD5 Hash PrefixerMD5 Hash Prefixer takes all the files in a s ...
-
Given a registration code, or something important like that, which often contains information encoded in the alphanumeric string itself, it is sometimes qui ...
-
Given a registration code, or something important like that, which often contains information encoded in the alphanumeric string itself, it is sometimes qui ...
-
Andrew Walker crafted this handy little PHP function which can convert a UTF-16 encoded string into a more PHP-friendly UTF-8 encoded string. The functio ...