我正在使用 rijndeal 加密和解密一些数据!但它给了我这个错误:
填充无效且无法移除。
我搜索了很多,但没有任何帮助我解决这个错误!tis 是我的加密/解密代码:
public string Encrypt(string text)
{
mainRM = new System.Security.Cryptography.RijndaelManaged();
mainRM.BlockSize = 256;
mainRM.KeySize = 256;
memorystream = new System.IO.MemoryStream();
ICryptoTransform icrypt = mainRM.CreateEncryptor(key, iv);
CryptoStream cryptstream = new CryptoStream(memorystream, icrypt, CryptoStreamMode.Write);
cryptstream.FlushFinalBlock();
System.IO.StreamWriter sw = new System.IO.StreamWriter(cryptstream);
sw.Write(text);
return Convert.ToBase64String(memorystream.ToArray());
}
public string Decrypt(string CryptedText)
{
string custinfo;
System.IO.StreamReader streamreader;
mainRM = new RijndaelManaged();
mainRM.BlockSize = 256;
mainRM.KeySize = 256;
memorystream = new System.IO.MemoryStream(Convert.FromBase64String(CryptedText));
ICryptoTransform icrypt = mainRM.CreateDecryptor(key, iv);
memorystream.Position = 0;
CryptoStream cryptstream = new CryptoStream(memorystream, icrypt, CryptoStreamMode.Read);
cryptstream.FlushFinalBlock();
streamreader = new System.IO.StreamReader(cryptstream);
custinfo = streamreader.ReadToEnd();
return custinfo;
}
谁能帮我?