第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

填充無效,無法刪除?

填充無效,無法刪除?

C#
猛跑小豬 2019-08-12 18:35:52
填充無效,無法刪除?我已經(jīng)在線查看了這個異常對我的程序的意義,但似乎無法找到解決方案或者為什么它會發(fā)生在我的特定程序中。我一直在使用我的msdn提供的示例,用于使用Rijndael算法加密和解密XmlDocument。加密工作正常,但是當我嘗試解密時,我得到以下異常:填充無效,無法刪除誰能告訴我我能做些什么來解決這個問題?我的代碼是我獲取密鑰和其他數(shù)據(jù)的地方。如果cryptoMode為false,它將調用decrypt方法,這是異常發(fā)生的地方: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();
查看完整描述

3 回答

?
臨摹微笑

TA貢獻1982條經(jīng)驗 獲得超2個贊

Rijndael / AES是一個塊密碼。它以128位(16個字符)塊加密數(shù)據(jù)。 加密填充用于確保消息的最后一個塊始終是正確的大小。

您的解密方法期望其默認填充是什么,并且沒有找到它。正如@NetSquirrel所說,您需要為加密和解密顯式設置填充。除非您有其他理由,否則請使用PKCS#7填充。


查看完整回答
反對 回復 2019-08-12
?
慕虎7371278

TA貢獻1802條經(jīng)驗 獲得超4個贊

請確保您使用的密鑰進行加密解密相同的。填充方法即使沒有明確設置,仍應允許正確的解密/加密(如果沒有設置它們將是相同的)。但是,如果由于某種原因使用不同的密鑰集進行解密而不是用于加密,則會出現(xiàn)此錯誤:

填充無效,無法刪除

如果您使用某種算法來動態(tài)生成無效的密鑰。加密和解密都需要相同。一種常見的方法是讓調用者在加密方法類的構造函數(shù)中提供密鑰,以防止加密/解密過程有任何創(chuàng)建這些項的過程。它側重于手頭的任務(加密和解密數(shù)據(jù)),并要求調用者提供ivkey提供。


查看完整回答
反對 回復 2019-08-12
?
眼眸繁星

TA貢獻1873條經(jīng)驗 獲得超9個贊

為了人們搜索的好處,可能值得檢查被解密的輸入。在我的情況下,發(fā)送用于解密的信息(錯誤地)作為空字符串進入。它導致填充錯誤。

這可能與rossum的答案有關,但認為值得一提。


查看完整回答
反對 回復 2019-08-12
  • 3 回答
  • 0 關注
  • 630 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號