gpt4 book ai didi

c# - 需要解密 SAML 响应

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:14 25 4
gpt4 key购买 nike

我需要使用 C# 集成单点登录,我从 IdP 获得 SAML 响应,我需要解密 SAML 响应(加密:TripleDes)。我需要使用证书中的私钥解密。

当我尝试使用证书 key 解密时,出现错误: key 大小无效。有没有一种标准方法可以将私钥转换为 TripleDes 的有效大小?例如

我应该使用前 24 个字节还是应该使用 MD5 哈希?是否有任何开放库可用于在 C# 中解密 SAML 响应?

以下是我从 IdP 收到的 XML:

<saml:EncryptedAssertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
<X509Certificate>Signing certificate goes here==</X509Certificate>
</X509Data>
</KeyInfo>
<CipherData>
<CipherValue>Cipher value goes here==</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>cipher value goes here=</CipherValue>
</CipherData>
</EncryptedData>
</saml:EncryptedAssertion>

代码片段:

byte[] inputArray = Convert.FromBase64String(EncryptedData);
TripleDESCryptoServiceProvider tripleDES = (TripleDESCryptoServiceProvider)cert.PrivateKey;

异常出现在第二行。我目前没有使用任何第三方工具。

最佳答案

尝试将您的代码片段切换为:

byte[] inputArray = Convert.FromBase64String(EncryptedData);
var cryptoProvider = (RSACryptoServiceProvider)cert.PrivateKey;

关于c# - 需要解密 SAML 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23952761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com