你好需要帮助我有代码md5来做密码并解密现在这个代码我把它放在模块中需要从表单调用我怎么做(vb.net)
Imports System.Security.Cryptography
Imports System.Text
Module Crypt
Public Function Encrypt(ByVal toEncrypt As String, ByVal key As String, ByVal useHashing As Boolean) As String
Dim keyArray As Byte()
Dim toEncryptArray As Byte() = UTF8Encoding.UTF8.GetBytes(toEncrypt)
If useHashing = True Then
Dim hashmd5 As New MD5CryptoServiceProvider()
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key))
Else
keyArray = UTF8Encoding.UTF8.GetBytes(key)
End If
Dim tdes As New TripleDESCryptoServiceProvider()
tdes.Key = keyArray
tdes.Mode = CipherMode.ECB
tdes.Padding = PaddingMode.PKCS7
Dim cTransform As ICryptoTransform = tdes.CreateEncryptor()
Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
Return (Convert.ToBase64String(resultArray, 0, resultArray.Length))
End Function
Public Function Decrypt(ByVal toDecrypt As String, ByVal key As String, ByVal useHashing As Boolean) As String
Dim keyArray As Byte()
Dim toEncryptArray As Byte() = Convert.FromBase64String(toDecrypt)
If useHashing = True Then
Dim hashmd5 As New MD5CryptoServiceProvider()
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key))
Else
keyArray = UTF8Encoding.UTF8.GetBytes(key)
End If
Dim tdes As New TripleDESCryptoServiceProvider()
tdes.Key = keyArray
tdes.Mode = CipherMode.ECB
tdes.Padding = PaddingMode.PKCS7
Dim cTransform As ICryptoTransform = tdes.CreateDecryptor()
Dim resultArray As Byte() = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length)
Return UTF8Encoding.UTF8.GetString(resultArray)
End Function
End Module
答案 0 :(得分:-2)
Module = static class
static =在vb.net中共享
NotInheritable Class SecurityModule
Private Sub New()
End Sub
Public Shared Function Encrypt(parameters) As String
// Your implementation
End Function
Public Shared Function Decrypt(parameters) As String
// Your implementation
End Function
End Class
NotInheritable就像是密封的。共享就像静态类的方法。
致电
SecurityModule.Encrypt(...)
希望这有帮助!