📄 wdacrypto.vb
字号:
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Public Class WDACrypto
Implements IDisposable
Private bytKey() As Byte
Private bytIV() As Byte
Public Sub New(ByVal Key() As Byte, ByVal IV() As Byte)
bytKey = Key
bytIV = IV
End Sub
Public Sub Dispose() Implements System.IDisposable.Dispose
End Sub
Public Function Encrypt(ByVal strToEncrypt As String) As String
Try
'Initialize a new instance of the TripleDESCryptoServiceProvider class
Dim objTripleDES As New TripleDESCryptoServiceProvider
'Convert the input string to a byte array
Dim bytInput() As Byte = Encoding.UTF8.GetBytes(strToEncrypt)
'Initialize a new instance of the MemoryStream class
Dim objOutputStream As New MemoryStream
'Encrypt the byte array
Dim objCryptoStream As New CryptoStream(objOutputStream, _
objTripleDES.CreateEncryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
objCryptoStream.Write(bytInput, 0, bytInput.Length)
objCryptoStream.FlushFinalBlock()
'Return the byte array as a Base64 string
Return Convert.ToBase64String(objOutputStream.ToArray())
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
Public Function Decrypt(ByVal strToDecrypt As String) As String
Try
'Initialize a new instance of the TripleDESCryptoServiceProvider class
Dim objTripleDES As New TripleDESCryptoServiceProvider
'Convert the input string to a byte array
Dim inputByteArray() As Byte = Convert.FromBase64String(strToDecrypt)
'Initialize a new instance of the MemoryStream class
Dim objOutputStream As New MemoryStream
'Decrypt the byte array
Dim objCryptoStream As New CryptoStream(objOutputStream, _
objTripleDES.CreateDecryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
objCryptoStream.Write(inputByteArray, 0, inputByteArray.Length)
objCryptoStream.FlushFinalBlock()
'Return the byte array as a string
Return Encoding.UTF8.GetString(objOutputStream.ToArray())
Catch ExceptionErr As Exception
Throw New System.Exception(ExceptionErr.Message, _
ExceptionErr.InnerException)
End Try
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -