填充无效,无法删除?
我已经在线查看了这个异常对我的程序的意义,但似乎无法找到解决方案或者为什么它会发生在我的特定程序中。我一直在使用我的msdn提供的示例,用于使用Rijndael算法加密和解密XmlDocument。加密工作正常,但是当我尝试解密时,我得到以下异常:
填充无效,无法删除
谁能告诉我我能做些什么来解决这个问题?我的代码是我获取密钥和其他数据的地方。如果cryptoMode为false,它将调用decrypt方法,这是异常发生的地方:
public void Cryptography(XmlDocument doc, bool cryptographyMode){ RijndaelManaged key = null; try { // Create a new Rijndael key. key = new RijndaelManaged(); const string passwordBytes = "Password1234"; //password here byte[] saltBytes = Encoding.UTF8.GetBytes("SaltBytes"); Rfc2898DeriveBytes p = new Rfc2898DeriveBytes(passwordBytes, saltBytes); // sizes are devided by 8 because [ 1 byte = 8 bits ] key.IV = p.GetBytes(key.BlockSize/8); key.Key = p.GetBytes(key.KeySize/8); if (cryptographyMode) { Ecrypt(doc, "Content", key); } else { Decrypt(doc, key); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { // Clear the key. if (key != null) { key.Clear(); } }}private void Decrypt(XmlDocument doc, SymmetricAlgorithm alg){ // Check the arguments. if (doc == null) throw new ArgumentNullException("Doc"); if (alg == null) throw new ArgumentNullException("alg"); // Find the EncryptedData element in the XmlDocument. XmlElement encryptedElement = doc.GetElementsByTagName("EncryptedData")[0] as XmlElement; // If the EncryptedData element was not found, throw an exception. if (encryptedElement == null) { throw new XmlException("The EncryptedData element was not found."); } // Create an EncryptedData object and populate it. EncryptedData edElement = new EncryptedData(); edElement.LoadXml(encryptedElement); // Create a new EncryptedXml object. EncryptedXml exml = new EncryptedXml();
临摹微笑
慕虎7371278
眼眸繁星
相关分类