专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

VB2005里的MD5加密(50分)解决方法

发布时间:2011-06-23 15:59:24 文章来源:www.iduyao.cn 采编人员:星星草
VB2005里的MD5加密(50分)
在vb2005里用下面代码算出的32位MD5值和http://www.chinaue.com/tool/md5/md5.htm
http://www.xmd5.org/Encrypt_cn.htm   里算出的不一样
Dim   MD5   As   String   =   " "
                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  
                        MD5   +=   Hex(hashvalue(i)).ToLower
                Next
                Return   MD5
请高手帮忙看看什么地方出错了,先谢谢了!

------解决方案--------------------
Imports System.Text
Imports System.Security.Cryptography
Public Class ClsMD5
Private md5 As New MD5CryptoServiceProvider
Private mdByte() As Byte
Private pwd() As Byte
Public Function clsmd5(ByVal a As String) As String
Try
pwd = (New ASCIIEncoding).GetBytes(a)
mdByte = md5.ComputeHash(pwd)
Return (New ASCIIEncoding).GetString(mdByte)
Catch ex As Exception
MsgBox(ex.Message)
Return 0
End Try
End Function
End Class


这个没错!!!!!!!
------解决方案--------------------
Imports System.Security.Cryptography
Imports System.Text
Module 加密模块
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 '32位
For i = 0 To 15
sBuilder.Append(data(i).ToString( "x2 "))
Next i
End If
Return sBuilder.ToString()
End Function
End Module

看看这个能用吗?
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: