VB.NET中MD5加密

前端之家收集整理的这篇文章主要介绍了VB.NET中MD5加密前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    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


原文载于:http://blog.sina.com.cn/s/blog_3cb3c25401009k0e.html 江缘的BLOG

猜你在找的VB相关文章