【发布时间】:2019-10-29 14:14:57
【问题描述】:
我想在Digital Signature 中添加包含public key 的其他RsaKeyValue KeyInfo。
然后用户不必保存certificate - 而是可以使用public key 来检查文档的有效性。
到目前为止,这是我的签名功能:
public static void SignXmlDocumentWithCertificate(XmlDocument xmlDoc, X509Certificate2 cert)
{
SignedXml signedXml = new SignedXml(xmlDoc);
//we will sign it with private key
signedXml.SigningKey = cert.PrivateKey;
Reference reference = new Reference();
//sign the entire doc
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
signedXml.AddReference(reference);
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new KeyInfoX509Data(cert));
keyInfo.(cert);
signedXml.KeyInfo = keyInfo;
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
}
在本文档中它是用 C++ 编写的: https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.xml.rsakeyvalue?view=netframework-4.8
向下滚动做部分
// 添加一个 RSAKeyValue KeyInfo(可选;帮助收件人找到要验证的密钥)。
如何在 C# 中做到这一点?
如何将这个可选的密钥信息与公钥一起添加?
【问题讨论】:
-
看看我的解决方案是否有帮助:stackoverflow.com/questions/46722997/…