0
我使用rijndeal來加密和解密一些數據!但它給了我這個錯誤:rijndeal算法解密給填充錯誤
Padding is invalid and cannot be removed.
我搜索了很多,但沒有任何幫助我解決這個錯誤! 那朵是我的加密/解密代碼:
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;
}
誰能幫助我?
SO用戶在將黑客破解爲試圖解決問題的碎片後,往往會發布他們的代碼。發佈無效的第一個版本,而不是您添加無意義代碼的版本。 – 2013-04-26 12:25:34
無意義的代碼? – 2013-04-26 13:53:03
將文本寫入流之後,是否需要調用FlushFinalBlock()? – 2013-04-26 14:00:54