如何解密使用 aes128-gcm

问题描述

我收到了一个 SAML2 响应,其中包含一个 EncryptedData 元素,看起来像下面的 xml 块。数据使用 aes128-gcm 加密。我需要解密数据。

我最接近解决方案的似乎是 this 代码,但我未能向 EncryptedXml.DecryptData 方法提供 SymmetricAlgorithm 实例。

我有一个 pfx 文件和它的密码,但如何从中获取 SymmetricAlgorithm?

    var encryptedElement = rawResponse.GetElementsByTagName("xenc:EncryptedData")[0] as XmlElement;
    var encryptedData = new EncryptedData();
    encryptedData.LoadXml(encryptedElement);

    var encryptedDoc = new EncryptedXml();
    encryptedDoc.DecryptData(encryptedData,xxx);

这里是xml

<xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="_08c07f24af25bc28efc32a88e78cecba" Type="http://www.w3.org/2001/04/xmlenc#Element">
    <xenc:EncryptionMethod xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Algorithm="http://www.w3.org/2009/xmlenc11#aes128-gcm" />
    <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <xenc:EncryptedKey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Id="_32cb20aabf0978078c5bce424a64daba" Recipient="MyEntityId">
            <xenc:EncryptionMethod xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
                <ds:DigestMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
            </xenc:EncryptionMethod>
            <ds:KeyInfo>
                <ds:X509Data>
                    <ds:X509Certificate>MIIDUzCC...bVJ7b</ds:X509Certificate>
                </ds:X509Data>
            </ds:KeyInfo>
            <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
                <xenc:CipherValue>qQye...cFuI6RUw==</xenc:CipherValue>
            </xenc:CipherData>
        </xenc:EncryptedKey>
    </ds:KeyInfo>
    <xenc:CipherData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
        <xenc:CipherValue>M3nM44...r</xenc:CipherValue>
    </xenc:CipherData>
</xenc:EncryptedData>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)