Malformed Reference Element: Digital Signature

Asked

Viewed 1,817 times

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?

  • 1

    The ID now needs to start with letter, can no longer be started with numbers and can no longer contain special characters...

1 answer

2


The update of windows 7 to be removed (palliative solution), is the KB3135983.

In case it is she who makes this new "request" security in xml now.

It is confirmed that the ID needs to start with letter only, and cannot contain special characters in your ID.

If you use the palliative solution, it is only recommended to also hide the update to avoid possible machine returns. Follow the image in windows update making it possible to disable the specific update (even in automatic mode).

Note: It is worth mentioning that the removal of the update is only for the system to continue in its operation until it is updated removing the later problem, obtaining the least impact to the end user (directly or indirectly).

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.