luisgoncalves / xades4j

A Java library for XAdES signature services
GNU Lesser General Public License v3.0
109 stars 65 forks source link

Extraer el valor de signatureValue id #182

Closed ialvira closed 5 years ago

ialvira commented 5 years ago

hola luis:

estoy usando tu libreria para firmar documentos xml en formato xades/epes y los firma correctamente.

el siguiente paso es una vez firmado extraer el SignatureValue id del archivo xml ya firmado

he intentado acceder con un document.getElementsByTagName("Signature") pero me devuelve null quiza es por que mi xsd no integra la firma

puedo usar tu libreria para extraer el signatureValue aunque haya que extraelo del signer??

gracias

ialvira commented 5 years ago

Hello Luis I am using your library to sign xml documents in xades / epes and the signature correctly. the next step is once signed extract the SignatureValue id from the xml file already signed He tried to access a document.elementsByTagName ("Signature") but it returns null if it is for that my xsd does not integrate the signature Can I use your library to extract the signature Value even if it has to be extracted from the signer? Thank you

ialvira commented 5 years ago
public void test(String ruta) {
      File fXmlFile = new File(ruta);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder;
        try {
            dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(fXmlFile);            
            //optional, but recommended
            //read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
            doc.getDocumentElement().normalize();

            System.out.println("Root element :" + doc.getDocumentElement().getNodeName());

            NodeList nList= doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
             Element signatureNode = (Element)doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "SignatureValue").item(0);
             System.out.println(signatureNode);

            System.out.println("----------------------------");

            for (int temp = 0; temp < nList.getLength(); temp++) {

                Node nNode = nList.item(temp);

                System.out.println("\nCurrent Element :" + nNode.getNodeName());

                if (nNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element eElement = (Element) nNode;
//
//                  System.out.println("Staff id : " + eElement.getAttribute("HuellaAutenticacion"));
//                  System.out.println("First Name : " + eElement.getElementsByTagName("Signature id").item(0).getTextContent());
                    //System.out.println("First Name : " + eElement.getElementsByTagName("TipoDesglose").item(0).getTextContent());
                    System.out.println("Last Name : " + eElement.getElementsByTagName("SignatureValue").item(0).getTextContent());

                }
            }
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

  }

not work

luisgoncalves commented 5 years ago

Hello,

Try setting the document build factory to be namespace aware: dbFactory.setNamespaceAware(true).

Note: this isn't really an issue with xades4j...

ialvira commented 5 years ago

thanks you a lot of... its workin now sorry im noob heheh