把下面的代码写到全局代码,然后调用 msgbox(MD5("12345678", 32))
Public Function MD5(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