Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EncryptedXml OAEP-空引用问题_C#_Xml_C# 4.0_Encryption - Fatal编程技术网

C# EncryptedXml OAEP-空引用问题

C# EncryptedXml OAEP-空引用问题,c#,xml,c#-4.0,encryption,C#,Xml,C# 4.0,Encryption,因此,我对使用OAEP解密EncryptedXml有一个问题。我有一部分代码加密一些xml,如下所示: ... byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, true); EncryptedData edElement = new EncryptedData(); edElement.Type = EncryptedXml.XmlE

因此,我对使用OAEP解密EncryptedXml有一个问题。我有一部分代码加密一些xml,如下所示:

        ...
        byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, true);

        EncryptedData edElement = new EncryptedData();
        edElement.Type = EncryptedXml.XmlEncElementUrl;
        edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncRSAOAEPUrl);
        ...
        EncryptedXml exml = new EncryptedXml(document);
        var provider = (RSA)_certificate.PrivateKey;
        exml.AddKeyNameMapping("rsaKey", provider);
        exml.DecryptDocument();
当我尝试像这样解密它时:

        ...
        byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, true);

        EncryptedData edElement = new EncryptedData();
        edElement.Type = EncryptedXml.XmlEncElementUrl;
        edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncRSAOAEPUrl);
        ...
        EncryptedXml exml = new EncryptedXml(document);
        var provider = (RSA)_certificate.PrivateKey;
        exml.AddKeyNameMapping("rsaKey", provider);
        exml.DecryptDocument();
EncryptedXml引发异常:

对象引用未设置为对象的实例

堆栈中的跟踪是以下方法:在System.Security.Cryptography.Xml.EncryptedXml.GetDecryptionKeyEncryptedData encryptedData中,字符串对称算法URI

当我使用EncryptedXml.XmlEncAES256Url时,一切都很好,并且工作正常。但我需要使用EncryptedXml.xmlencsoaepurl


知道怎么回事吗?

我只在第一个代码块中看到一个会话密钥,在另一个代码块中看到一个RSA私钥。要么是您发布的代码太少,要么是两个键之间存在一些奇怪的不匹配。我发现了问题所在。我用非对称密钥和对称aes256密钥加密数据。所以我换了加密方法,一切都很好。现在,对我来说,用非对称密钥对密钥进行加密,用对称会话密钥对数据进行加密,然后用私钥对密钥进行解密,用解密后的密钥对数据进行解密是有意义的。这只是一个愚蠢的错误。很高兴你用1275513解决了这个问题,如果你愿意,我可以把我的评论作为一个答案,或者如果你愿意,你可以自己回答。愚蠢的错误是你找不到的: