VB.NET里的MD5加密函数

来源:互联网 发布:足球意大利克德国知乎 编辑:程序博客网 时间:2024/06/10 00:03

   Imports System.Security.Cryptography

 Public Function Md5hash_String(ByVal InputString As String) As String
        Dim code, MD5
        Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(InputString)
        Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash)
        Dim i As Integer
        For i = 0 To 15 '选择32位字符的加密结果
            MD5 += Hex(hashvalue(i)).ToLower
        Next
        Return MD5
    End Function

原创粉丝点击