3
I ended up having the same problem about a post already made here, but they see a question next to what was posted in the article. Which windows update would be to remove among those cited in this article? (the removal would be a palliative until solving the problem)
Aside from the question about the article, follow the code that I’m in trouble.
public void AssinarElementos(XmlDocument Document, X509Certificate2 x509, string ParentElementName, string ElementName, string AttributeName)
{
XmlElement elInf;
string elInfID;
SignedXml elSigned;
RSACryptoServiceProvider Key;
KeyInfo keyInfo = new KeyInfo();
// Retira chave privada ligada ao certificado
Key = ((RSACryptoServiceProvider)(x509.PrivateKey));
keyInfo.AddClause(new KeyInfoX509Data(x509));
foreach (XmlElement ele in Document.GetElementsByTagName(ParentElementName))
{
elInf = ((XmlElement)(ele.GetElementsByTagName(ElementName)[(ele.GetElementsByTagName(ElementName).Count - 1)]));
elInfID = elInf.Attributes.GetNamedItem(AttributeName).Value;
elSigned = new SignedXml(elInf);
// Seta chaves
elSigned.SigningKey = Key;
elSigned.KeyInfo = keyInfo;
// Cria referencia
Reference reference = new Reference();
reference.Uri = ("#" + elInfID);
// Adiciona tranformacao a referencia
reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
reference.AddTransform(new XmlDsigC14NTransform(false));
// Adiciona referencia ao xml
elSigned.AddReference(reference);
// Calcula Assinatura
elSigned.ComputeSignature();
// Adiciona assinatura
ele.AppendChild(Document.ImportNode(elSigned.GetXml(), true));
}
}
An error of Elemento de referência mal formado.
, on the line where the elSigned.ComputeSignature();
(I did a test on a machine with windows 10 and worked perfectly).
One of the answers in article commented on the character /
which would be invalid and probably other characters like :;^~,
would be considered invalid. I use the character #
to id would be a problem?
The ID now needs to start with letter, can no longer be started with numbers and can no longer contain special characters...
– user44277