填充无效,无法删除

来自评论:

一旦我手动将填充设置为NONE,问题就消失了


这段代码怎么了? VS2010确实编译它,但从VS2010运行时出错,说cs.close()填充无效,任何人都可以帮忙吗? 谢谢

public static byte[] Decrypt(byte[] cipherData,byte[] Key, byte[] IV) { MemoryStream ms = new MemoryStream(); Rijndael alg = Rijndael.Create(); alg.Key = Key; alg.IV = IV; alg.Padding = PaddingMode.PKCS7, ; CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(cipherData, 0, cipherData.Length); cs.Close(); byte[] decryptedData = ms.ToArray(); return decryptedData; 

你试过以下吗?

 cs.Write(cipherData, 0, cipherData.Length); //Add this line: cs.FlushFinalBlock(); cs.Close();