Я хотел бы добавить дополнительные RsaKeyValue KeyInfo
, включающие public key
в Digital Signature
.
. Пользователь не должен сохранять certificate
- вместо этого он может использовать * 1007. * чтобы проверить действительность документа.
Итак, вот моя функция подписи:
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 #?
Как добавить этот необязательный keyinfo с открытым ключом?