Assinatura XMl

2 respostas
P

Bom dia pessoal,

Estou com um probleminha na assinatura da NFe, estou convertendo meu xml em string e depois tentando extrair os bytes dele, mas esta me retornando null, segue o código:

private static String lerXML(String fileXML) throws IOException {  
        String linha = "";  
        StringBuilder xml = new StringBuilder();  
  
        BufferedReader in = new BufferedReader(new InputStreamReader(  
                new FileInputStream(fileXML)));  
        while ((linha = in.readLine()) != null) {  
            xml.append(linha);  
        }  
        in.close();  
  
        return xml.toString();  
    }
private Document documentFactory(String xml) throws SAXException,  
            IOException, ParserConfigurationException {  
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
        factory.setNamespaceAware(true);  
        Document document = factory.newDocumentBuilder().parse(  
                new ByteArrayInputStream(xml.getBytes()));  
        return document;  
    }
public String assinaEnviNFe(String xml, String certificado, String senha)  
            throws Exception {  
        Document document = documentFactory(xml);  
        XMLSignatureFactory signatureFactory = XMLSignatureFactory.getInstance("DOM");  
        ArrayList<Transform> transformList = signatureFactory(signatureFactory);  
        loadCertificates(certificado, senha, signatureFactory);  
  
        for (int i = 0; i < document.getDocumentElement().getElementsByTagName(NFE).getLength(); i++) {  
            assinarNFe(signatureFactory, transformList, privateKey, keyInfo, document, i);  
        }  
  
        return outputXML(document);  
    }

Ali no método assinaEnviNFe não entra no for por causa que me retorna null o Document, o que estou fazendo de errado???

Desde já agradeço.

2 Respostas

pedruhenrik

http://www.guj.com.br/java/237281-tutorial-consumir-webservice-nfe-20

espero q ajude.

att,

P

Cara ajudou bastante esse tuto, mas no meu caso estou com problemas na hora de assinar o xml, ali onde ele da um xml.getByte() ele me retorna [document]null, e o xml não está vazio.

Criado 28 de novembro de 2011
Ultima resposta 28 de nov. de 2011
Respostas 2
Participantes 2