System.Security之MD5加密、解密
因为时间的原因,只附加代码,代码可以直接使用
如有不同可留言,或发邮件给我 yeshenrenji@163.com
谢谢大家的来访
Imports System.Security.Cryptography
Imports System.Text
'解密
Public Function Decrypt3DES(ByVal strString As String, Optional ByVal strKey As String = "thsoft") As String
Decrypt3DES = ""
Dim DES As New TripleDESCryptoServiceProvider
Dim hashMD5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
DES.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strKey))
DES.Mode = CipherMode.ECB
Dim DESDecrypt As ICryptoTransform = DES.CreateDecryptor()
Dim result As String = ""
Try
Dim Buffer As Byte() = Convert.FromBase64String(strString)
result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
Catch ex As Exception
End Try
Decrypt3DES = result
End Function
'加密
Public Function Encrypt3DES(ByVal strString As String, Optional ByVal strKey As String = "thsoft") As String
Encrypt3DES = ""
Dim DES As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
Dim hashMD5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
DES.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strKey))
DES.Mode = CipherMode.ECB
Dim DESEncrypt As ICryptoTransform = DES.CreateEncryptor()
Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(strString)
Encrypt3DES = Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
End Function
#End Region

浙公网安备 33010602011771号