在下面的文章中,我试图遵循这个解决方案,以便能够使用CNG私钥作为我的SignedXml的签名密钥。

CustomSignedXml来源于SignedXml。但是,当我这样做并调用ComputeSignature方法时,我会得到异常
方法不是System.Security.Cryptography.RSA.DecryptValue(Byte[] supported.at )
at System.Security.Cryptography.Xml.SignedXml.**ComputeSignature**()正如堆栈跟踪提示的那样,方法不受支持,因此从DecryptValue抛出,我看到这是来自DecryptValue基类的一个不推荐的方法。我不能重写它来使用RSACng.Decrypt,因为RSACng是一个密封类。
我在这里错过了什么?
发布于 2016-04-19 03:12:19
在CLR安全问题页面中,SignedXml仍然缺少对RSACng的支持。然而,我的评论指向4.6.2预览。您可以使用GetRSAPrivateKey()来获取密钥(我认为它在4.6.1中已经是可以获得的),但这一次我没有获取“不支持的方法”异常。因此,最好的解决方案是将您的框架更新为4.6.2,下面的代码可以工作。
https://clrsecurity.codeplex.com/workitem/11073
private CustomSignedXml CreateSignedXml()
{
var signedXml = new CustomSignedXml(_documentToSign)
{
SigningKey = _signingCertificate.GetRSAPrivateKey(),
KeyInfo = CreateKeyInfo()
};
Reference reference = new Reference("");
reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
reference.DigestMethod = SecurityAlgorithms.Sha256Digest; // SignedXml.XmlDsigSHA256Url;
signedXml.SignedInfo.CanonicalizationMethod = SecurityAlgorithms.ExclusiveC14n;
signedXml.SignedInfo.SignatureMethod = SecurityAlgorithms.RsaSha256Signature; // SignedXml.XmlDsigRSASHA256Url
signedXml.AddReference(reference);
return signedXml;
}https://stackoverflow.com/questions/36686950
复制相似问题