'通过MsgBox(MD5Encrypt2("12345678", 32)) 调用
Public Function MD5Encrypt2(ByVal strSource As String, ByVal Code As Int16) As String
Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(strSource)
Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash)
Dim ATR As String = ""
Dim i As Integer
Select Case Code
Case 16 '选择16位字符的加密结果
For i = 4 To 11
ATR &= Hex(hashvalue(i)).PadLeft(2, "0").ToLower
Next
Case 32 '选择32位字符的加密结果
For i = 0 To 15
ATR &= Hex(hashvalue(i)).PadLeft(2, "0").ToLower
Next
Case Else 'Code错误时,返回全部字符串,即32位字符
For i = 0 To 15
ATR &= Hex(hashvalue(i)).PadLeft(2, "0").ToLower
Next
End Select
Return ATR
End Function