Using VB.Net To Encrypt LDAP MD5 Passwords

When passwords are stored in an LDAP directory they are stored encrypted. LDAP supports different types of hashing, but I chose to use MD5.  The LDAP implementation is to use Base 64 encoding. Below is a simple function I use to convert the plain text password into a hashed string ready to be added to LDAP.

Public Shared Function EncryptPassword(ByVal value As String) As String

        Dim cryptProvider As New MD5CryptoServiceProvider
        Dim b As Byte() = Text.UTF8Encoding.UTF8.GetBytes(value)
        Dim encoded As Byte() = cryptProvider.ComputeHash(b)
        Dim hash As String = Convert.ToBase64String(encoded)

        Return hash

End Function


Leave a Reply


foreandaft