Hello!. I am trying to sign an xml with a key (.pfx) and when I sent it to who should receive it I get in response "Incorrect reference digest value". I am working with C# and I need your help to solve my problem. Here is my code, which I got (in part) from MSDN
private static void SignXml(XmlDocument xmlDoc, X509Certificate2 uidCert)
{
RSACryptoServiceProvider rsaKey = (RSACryptoServiceProvider)uidCert.PrivateKey;
// Create a SignedXml object .
SignedXml signedXml = new SignedXml(xmlDoc);
signedXml.SigningKey = rsaKey;
Reference reference = new Reference();
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
signedXml.AddReference(reference);
KeyInfo keyInfo = new KeyInfo();
KeyInfoX509Data clause = new KeyInfoX509Data();
clause.AddSubjectName(uidCert.Subject);
clause.AddCertificate(uidCert);
keyInfo.AddClause(clause);
signedXml.KeyInfo = keyInfo;
// Compute signature.
signedXml.ComputeSignature();
XmlElement xmlDigitalSignature = signedXml.GetXml();
xmlDigitalSignature.Prefix = "ds";
signedXml.ComputeSignature();
MessageBox.Show(signedXml.GetXml().InnerXml);
xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
//check signature
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("ds:Signature");
if (nodeList.Count <= 0)
{
MessageBox.Show("Verification failed: No Signature was found in the document.");
}
else if (nodeList.Count >= 2)
{
MessageBox.Show("Verification failed: More that one signature was found for the document.");
}
else
{
signedXml.LoadXml((XmlElement)nodeList[0]);
if (signedXml.CheckSignature())
{
MessageBox.Show("signature ok");
}
else
{
MessageBox.Show("signature failed");
}
}
}
By the way, I could not donate because my debit card was rejected...???