« HTTP POST request with PHP CURL | Home | Find the Oracle object by name »

MD5 function for encrypting a string in VB.NET


Imports Microsoft.VisualBasic
Imports System.Security.Cryptography
Imports System.IO

Public Class CommonFunctions2
Public Shared Function MD5Encrypt(ByVal str As String) As String

'Imports System.Security.Cryptography

Dim md5 As MD5CryptoServiceProvider
Dim bytValue() As Byte
Dim bytHash() As Byte
Dim strOutput As String
Dim i As Integer

' Create New Crypto Service Provider Object
md5 = New MD5CryptoServiceProvider

' Convert the original string to array of Bytes
bytValue = System.Text.Encoding.UTF8.GetBytes(str)

' Compute the Hash, returns an array of Bytes
bytHash = md5.ComputeHash(bytValue)
md5.Clear()

For i = 0 To bytHash.Length - 1
'don't lose the leading 0
strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
Next

MD5Encrypt = strOutput

End Function
End Class

Topics: Hashing, VB, VB.NET | Submitter: admin

One Response to “MD5 function for encrypting a string in VB.NET”

  1. » Blog Database Connected!!! Says:
    August 11th, 2008 at 8:48 am

    [...] This solution is taken from here. [...]

Comments

You must be logged in to post a comment.