vb2005 md5
场景:VB2005里的MD5加密(50分)解决方法
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
看看这个能用吗?
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
看看这个能用吗?