以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 求助,全局代码报错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=158680) |
-- 作者:wandongliang -- 发布时间:2020/11/28 21:37:00 -- 求助,全局代码报错 在全局代码中写了一个函数,是根据他人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 |
-- 作者:有点蓝 -- 发布时间:2020/11/29 20:49:00 -- 原c#代码发上来 |
-- 作者:wandongliang -- 发布时间:2020/11/29 23:06:00 -- 原c#版本 public string AES_decrypt(string encryptedDataStr, string key, string iv) { RijndaelManaged rijalg = new RijndaelManaged(); //----------------- //设置 cipher 格式 AES-128-CBC rijalg.KeySize = 128; rijalg.Padding = PaddingMode.PKCS7; rijalg.Mode = CipherMode.CBC; rijalg.Key = Convert.FromBase64String(key); rijalg.IV = Convert.FromBase64String(iv); byte[] encryptedData= Convert.FromBase64String(encryptedDataStr); //解密 ICryptoTransform decryptor = rijalg.CreateDecryptor(rijalg.Key, rijalg.IV); string result; using (MemoryStream msDecrypt = new MemoryStream(encryptedData)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { result;= srDecrypt.ReadToEnd(); } } } return result; } |
-- 作者:有点蓝 -- 发布时间:2020/11/30 8:40:00 -- 代码没有问题。怎么用这个函数的?确定传入的key和iv是正确的 |