以下标记是SAML响应的一部分。我必须解密以下CipherValue。 我将CipherValue(字符串)传递给以下函数,但它没有返回正确的值,我做错了什么?
文档说:
从证书中获取私钥。
使用RSA / ECB / PKCS1Padding解密加密密钥。
(键是以下值)
private string RSADecryption(string dataToDecrypt)
{
String certificateLocation = ConfigurationManager.AppSettings.Get("CertificateLocation");
String certificateStore = ConfigurationManager.AppSettings.Get("CertificateStore");
string certificateSubject = ConfigurationManager.AppSettings.Get("CertificateSubject");
String decryptedKey = string.Empty;
try
{
X509Certificate2 encryptionCertificate = X509Utilities.GetCertificateBySubject(certificateSubject, certificateStore.ParseAsEnum<StoreName>(),
certificateLocation.ParseAsEnum<StoreLocation>());
if (encryptionCertificate == null )
Helper.LogMessage(" Did not find Encryption Certificate on the sserver " );
RSACryptoServiceProvider rsaProvider = (RSACryptoServiceProvider)encryptionCertificate.PrivateKey;
byte[] cipherbytes = Convert.FromBase64String(dataToDecrypt);
byte[] plainbytes = rsaProvider.Decrypt(cipherbytes, false);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
decryptedKey = enc.GetString(plainbytes);
}
catch (Exception e)
{
Helper.LogMessage(e.Message + " Key Parsing error. DataToDecrypt = " + dataToDecrypt);
throw e;
}
return decryptedKey;
&LT;的CipherData&GT;&LT;的CipherValue&GT; HQrhmJpbd0p32QjOFrOKQhNSr4q6bcbg + 9AhxJS6yZR19Nqh3VDMwOW2wsCBuSmFlv7WjR7TzW6URjINvNbv2nMfsKu3M9dscxhmGY + jVtUJ6sTf7FHdK9D76miAdq1EIsm0lNtdW5etMx / 85iMiFOObbyZuB8oaYeThToVjTUVYfNGQOJ99wvh8OL / 40eomDlKfwN4eQ88kVbY1eUO1OxEfQsUbDWyXvZEvBPmYUb7km + C6rX8UjsLUrqOOpXym9oi5dH + T + kAP2Rb5N16VRxJHPGF / gXeuD + Jq4FSGtjiiBE9qvBIFWkt4hYabSgUE3Li5DqMoH / P9 / EGqf6mpyvHjv8yJYRTpA // 5nM43z / KCUFX8VrFCXBp0N1Y40zpZWJW2y9fSIlyGyMas1ByBlkxpRgjqqnv1L + pZohYmKQsOILhM34TASzddYgeQbPfoAuC8i / 4cMWYDrO + NP + n5d97FZDPs3u3gMWefhWoSt0BSEwUCbaNmS9I39ihFwyT / 6rmurgLvfY0AaFz16Q3qQlH3yVdGR2j + A2spfJLyMrRcVTSff6HKa6LC7xUO9aBF2WpEw1mxI0QXMY2VMtSwdT4pzMc + itbDe9r4ZW9BZhA7qsBd0oOVRxxxNvOo9eIUlLyGRzvMbX + oOUiHkAm / oil7Vll5JzvlzVrc4dzzOUA = LT; /&的CipherValue GT;&LT; /&的CipherData GT;
答案 0 :(得分:1)
如果不能复制此项或没有生成加密值的代码,很难确定。我最好的猜测,即我已经看过太多次,是 text 编码问题。自那以后更有可能:
a)加密代码没有例外(例如填充错误);
b)这些天使用的ASCII非常多,如下所示:
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
可能无法返回您的期望。
所以我会尝试UFT8,Unicode ......以及所有变体(除非你在某处记录过这些)。