在全局代码中写了一个函数,是根据他人c#版本改写过来,但是最后的时候出现了报错,请问蓝版可能是哪里写错了?
Public Function AES_decrypt(ByVal encryptedDataStr As String, ByVal key As String, ByVal iv As String) As String
Dim rijalg As New System.Security.Cryptography.RijndaelManaged
rijalg.KeySize = 128
rijalg.Padding = System.Security.Cryptography.PaddingMode.PKCS7
rijalg.Mode =System.Security.Cryptography.CipherMode.CBC
rijalg.Key = Convert.FromBase64String(key)
rijalg.IV = Convert.FromBase64String(iv)
Dim encryptedData As Byte() = Convert.FromBase64String(encryptedDataStr)
Dim decryptor As System.Security.Cryptography.ICryptoTransform = rijalg.CreateDecryptor(rijalg.Key, rijalg.IV)
Dim result As String
Using msDecrypt As System.IO.MemoryStream = New System.IO.MemoryStream(encryptedData)
Using csDecrypt As System.Security.Cryptography.CryptoStream = New System.Security.Cryptography.CryptoStream(msDecrypt, decryptor, System.Security.Cryptography.CryptoStreamMode.Read)
Using srDecrypt As System.IO.StreamReader = New System.IO.StreamReader(csDecrypt)
result = srDecrypt.ReadToEnd() '测试显示这里出现问题,提示 填充无效,无法被移除
'MessageBox.Show("电话号码:" & result)
End Using
End Using
End Using
Return result
End Function