Imports System.Security.Cryptography
Function MD5(ByVal input As String, ByVal coda As Integer) As String
Dim md5Hasher As New MD5CryptoServiceProvider
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))
Dim sBuilder As New StringBuilder
Dim i As Integer
If coda = 16 Then
For i = 4 To 11
sBuilder.Append(data(i).ToString("x2"))
Next i
Else
For i = 0 To 15
sBuilder.Append(data(i).ToString("x2"))
Next i
End If
Return sBuilder.ToString()
End Function
msgbox (md5("想要加密的字符串",16)) '返回16位的密文
msgbox (md5("想要加密的字符串",32)) '返回32位的密文