我有一箇舊功能在2013年編寫的解密xml被另一個程序加密。EncryptedXml DecryptDocument方法錯誤.Net框架更新後
的代碼是真的簡單
public static void Decrypt(XmlDocument Doc)
{
// Check the arguments.
if (Doc == null)
throw new ArgumentNullException("Doc");
// Create a new EncryptedXml object.
EncryptedXml exml = new EncryptedXml(Doc);
// Decrypt the XML document.
exml.DecryptDocument();
}
它的工作就像一個魅力直到最近,我們的一些客戶開始他們的架構升級到4.6.2,因此該方法DecryptDocument()停止工作。現在它會拋出一個異常「算法組」無效「。如果我刪除.net框架4.6.2它再次工作。
此link中的示例代碼將重現該錯誤,它將成功加密,然後無法解密。
我正在使用A3證書,pendrive令牌。任何人都遇到過這個問題?在.net 4.6.2中有任何解決方法?
編輯1:
堆棧跟蹤:
at System.Security.Cryptography.CngAlgorithmGroup..ctor(String algorithmGroup) at System.Security.Cryptography.CngKey.get_AlgorithmGroup() at System.Security.Cryptography.RSACng..ctor(CngKey key) at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate) at System.Security.Cryptography.CngLightup.GetRSAPrivateKey(X509Certificate2 cert) at System.Security.Cryptography.Xml.EncryptedXml.DecryptEncryptedKey(EncryptedKey encryptedKey) at System.Security.Cryptography.Xml.EncryptedXml.GetDecryptionKey(EncryptedData encryptedData, String symmetricAlgorithmUri) at System.Security.Cryptography.Xml.EncryptedXml.DecryptDocument() at Criptografar.Program.Decrypt(XmlDocument Doc) in C:\Users\leoka\Documents\Visual Studio 2017\Projects\ConsoleApp4\Criptografar\Program.cs:line 152 at Criptografar.Program.Main(String[] args) in C:\Users\leoka\Documents\Visual Studio 2017\Projects\ConsoleApp4\Criptografar\Program.cs:line 83
你有完整的堆棧跟蹤嗎? –
客戶是否完全重建?讓客戶在項目中創建bin文件夾的副本。然後刪除bin文件夾並重新編譯。我懷疑錯誤是由於編譯器的依賴。編譯器對Net Version沒有任何依賴性,所以當安裝新的Net時需要完整的重新編譯。編譯器不會自動完成一個完整的編譯。 – jdweng
@jdweng即使在我的開發機器上也失敗了,我開始了一個新項目,粘貼了這個[link]的示例代碼(https://msdn.microsoft.com/en-us/library/ms148633(v = vs.110) )的.aspx)。它未能解密。 –