【发布时间】:2014-07-20 02:31:29
【问题描述】:
我需要使用 C# 集成 Single Sign On,我从 IdP 获得 SAML 响应,并且我需要解密 SAML 响应(加密:TripleDes)。我需要使用证书中的私钥解密。
当我尝试使用证书密钥解密时,它给了我错误:无效的密钥大小。是否有标准方法将私钥转换为 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>
代码sn-p:
byte[] inputArray = Convert.FromBase64String(EncryptedData);
TripleDESCryptoServiceProvider tripleDES = (TripleDESCryptoServiceProvider)cert.PrivateKey;
异常出现在第二行。我目前没有使用任何第三方工具。
【问题讨论】:
-
您是否使用任何用于 saml 的库?
-
不,我没有为 SAML 使用任何库。我不知道有任何适用于 .NET 的 SAML 库
-
我可以建议找一个吗?
-
您的代码没有意义。
EncryptedData是什么?cert是什么?假设cert是证书 - 证书不包含私钥,因此使用cert.PrivateKey从中获取一个是不可能的,即使假设有可能,将cert.PrivateKey转换为TripleDESCryptoServiceProvider也没有任何意义。 -
嗨丹尼尔 - 是的,请建议定位图书馆。
标签: c# encryption saml-2.0