求助,用vb.net做aes加密器的问题
我在做文本加解密功能,加密还好,几句话就完事了,可是解密时输入文本我不会转换成byte()。所以现在程序阶段处于只能加密不能解密。。放上网上的源码(自己无关紧要的改了几句),我希望可以对string进行解密
Private Function Encrypt(ByVal plainText As String, ByVal key As String) As String
Dim AES As New RijndaelManaged()
Dim MD5 As New MD5CryptoServiceProvider()
Dim plainTextData As Byte() = Encoding.Unicode.GetBytes(plainText)
Dim keyData As Byte() = MD5.ComputeHash(Encoding.UTF8.GetBytes(key))
Dim IVData As Byte() = MD5.ComputeHash(Encoding.UTF8.GetBytes("Alex Lee"))
AES.Key = keyData
AES.Mode = CipherMode.CFB
AES.Padding = PaddingMode.Zeros
Dim transform As ICryptoTransform = AES.CreateEncryptor()
Dim outputData As Byte() = transform.TransformFinalBlock(plainTextData, 0, plainTextData.Length)
Encrypt = Convert.ToBase64String(outputData)
End Function
'解密
Private Function Decrypt(ByVal cipherTextData As Byte(), ByVal key As String) As String
Dim AES As New RijndaelManaged()
Dim MD5 As New MD5CryptoServiceProvider()
Dim keyData As Byte() = MD5.ComputeHash(Encoding.UTF8.GetBytes(key))
Dim IVData As Byte() = MD5.ComputeHash(Encoding.UTF8.GetBytes("Alex Lee"))
AES.Key = keyData
AES.Mode = CipherMode.CFB
AES.Padding = PaddingMode.Zeros
Dim transform As ICryptoTransform = AES.CreateDecryptor()
Dim outputData As Byte() = transform.TransformFinalBlock(cipherTextData, 0, cipherTextData.Length)
Decrypt = Encoding.UTF8.GetString(outputData)
End Function