小编Leo*_*ier的帖子

.Net框架更新后的EncryptedXml DecryptDocument方法错误

我有一个2013年写的旧函数解密由另一个程序加密的xml.

代码非常简单

        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();

    }
Run Code Online (Sandbox Code Playgroud)

直到最近,我们的一些客户才开始将其框架升级到4.6.2,因此方法DecryptDocument()停止工作.现在它抛出异常"算法组''无效".如果我删除.net框架4.6.2它再次工作.

链接中的示例代码将重现错误,它将成功加密然后无法解密.

我正在使用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) …

c# xml encryption encryption-asymmetric x509certificate2

11
推荐指数
1
解决办法
610
查看次数