Ricardo Posted May 14, 2018 Report Share Posted May 14, 2018 Bom dia a todos Estou fazendo um trabalho para gerar arquivos xml para ser lido pelo o Reinf, estou usando uma classe postada aqui no fórum por nossos amigos. Essa usa métodos e propriedades da Capicom.DLL, aparentemente esta esta OK! No entanto o valor da da tag <DisgetValue> vem com um valor que me parece não esta correto. Gostaria se fosse possível que os amigos pudessem me ajudar nesse sentido. Pra ser mais claro abaixo esta parte do código que implementei: METHOD assinar_v2( oNode ) CLASS TMontaDocumentoXML LOCAL cTxtXml, oUtil cTxtXml := oNode:ToString( HBXML_STYLE_INDENT + HBXML_STYLE_THREESPACES ) ::nAlgorithm := CAPICOM_HASH_ALGORITHM_SHA_256 ::cDigestValue := ::HashData( cTxtXml ) ::cSignatureValue := ::Sign() return METHOD HashData( cData, nAlgorithm ) CLASS TMontaDocumentoXML LOCAL oCapicom, oUtil DEFAULT nAlgorithm := ::nAlgorithm IF cData == NIL cData := DToS( Date() ) + Time() ENDIF oUtil := CreateObject( "CAPICOM.Utilities.1" ) oCapicom := CreateObject( "CAPICOM.HashedData.1" ) oCapicom:Algorithm := nAlgorithm oCapicom:Hash( cData ) RETURN oUtil:Base64Encode( outil:HexToBinary( oCapicom:Value ) ) O retorno esta vindo dessa forma: <DigestValue>PwA/AD8APwA/AD8APwA/AD8APwA/AD8APwA/AD8APwA=</DigestValue> Acredito que era pra vir dessa: <DigestValue>+Dm6c8v+ZhocqLQ5miRzTsuDnP5TnmwCAkhvWvxiFdI=</DigestValue> Desde já agradeço qualquer ajuda. Quote Link to comment Share on other sites More sharing options...
kapiaba Posted May 14, 2018 Report Share Posted May 14, 2018 Veja se ajuda: http://www.pctoledo.com.br/forum/viewtopic.php?f=43&t=18664&p=120976&hilit=METHOD+HashData#p120976 http://www.pctoledo.com.br/forum/viewtopic.php?f=43&t=18664&p=119826&hilit=METHOD+HashData#p119826 Abs. Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 14, 2018 Author Report Share Posted May 14, 2018 Olá Kapiaba Foram desses link´s que utilizei pra montar a funcionalidade.. Vou dar uma revisada, se continuar posto alguma coisa. Obrigado assim mesmo. Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 16, 2018 Author Report Share Posted May 16, 2018 Olá Kabiaba Verifiquei meu código conforme o link que você sugeriu, e o retorno da classe HashData continua o mesmo. Pesquisei bastante e não encontrei uma solução pra esse problema. Se você tive mais uma dica ficaria muito grato. Abs. Quote Link to comment Share on other sites More sharing options...
kapiaba Posted May 16, 2018 Report Share Posted May 16, 2018 Veja se ajuda: http://www.pctoledo.com.br/forum/viewtopic.php?f=2&t=19208 Abs. Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 16, 2018 Author Report Share Posted May 16, 2018 Vou verificar amigo e te informo alguma coisa. Abs. Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 17, 2018 Author Report Share Posted May 17, 2018 Olá Kabiaba Verifiquei os fontes, observo que não é o fato de converter para a Base64, essa conversão parte de um número binário. Mas, o retorno do método vem uma seria de (?) interrogações. METHOD HashData( cData, nAlgorithm ) CLASS TMontaDocumentoXML ..... oUtil := CreateObject( "CAPICOM.Utilities.1" )oCapicom := CreateObject( "CAPICOM.HashedData.1" )oCapicom:Algorithm := CAPICOM_HASH_ALGORITHM_SHA_256oCapicom:Hash( cData ) // Resultado Hexadecimal cValorBin := outil:HexToBinary( oCapicom:Value ) /// ----> Aqui o retorno vem sempre "?????????????????" RETURN oUtil:Base64Encode( cValorBin ) Se outil:HexToBinary() estiver furado, a <digestvalue> será sempre PwA/AD8APwA/AD8APwA/AD8APwA/AD8APwA/AD8APwA= , minha necessidade é encontrar um algoritmo que me retorne a expressão correta em binário, ai pode ser que o encode Base64 funcione. Abs. Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 25, 2018 Author Report Share Posted May 25, 2018 Ola! Pessoal Não consegui resolver a falha no calculo do <digestValue> calculado pelo o método HexToBinary da Capicom.utilities. Tive que fazer um executável em C# passando o arquivo Xml que será assinado, o cnpj do certificado e o URI, dessa forma consegui assinar o xml. Grato Quote Link to comment Share on other sites More sharing options...
gilmer Posted May 25, 2018 Report Share Posted May 25, 2018 Esta ferramenta paga é muito bom para assinatura http://www.chilkatsoft.com Quote Link to comment Share on other sites More sharing options...
Ricardo Posted May 31, 2018 Author Report Share Posted May 31, 2018 Olá! pessoal Alguém pode postar um exemplo de xml assinado considerando esse envelopado, estou fazendo o que o manual do desenvolvedor do REINF pede, e não esta me trazendo resposta! Meu código é esse cXML := '<?xml version="1.0" encoding="UTF-8"?>' cXML += '<soap:Envelope ' cXML += 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' cXML += 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' cXML += 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' cXML += 'xmlns:sped="http://sped.fazenda.gov.br/">' cXML += '<soap:Header></soap:Header>' cXML += '<soap:Body>' cXML += ' <sped:RecepcaoLoteReinf_ReceberLoteEventos_InputMessage xmlns="http://sped.fazenda.gov.br/">' cXML += xXML cXML += ' </sped:RecepcaoLoteReinf_ReceberLoteEventos_InputMessage>' cXML += '</soap:Body>' cXML += '</soap:Envelope>' linkWS := "https://preprodefdreinf.receita.fazenda.gov.br/WsREINF/RecepcaoLoteReinf.svc" cSOAPAction := "http://sped.fazenda.gov.br/RecepcaoLoteReinf/ReceberLoteEventos" // ------------------------------- oDOMDoc := CreateObject( 'MSXML2.DOMDocument.5.0' ) oDOMDoc:async := .F. oDOMDoc:validateOnParse := .T. oDOMDoc:resolveExternals := .F. oDOMDoc:preserveWhiteSpace := .T. oDOMDoc:LoadXML(cXML) // -------------------------- oServerWS := CreateObject( 'MSXML2.ServerXMLHTTP.5.0' ) oServerWS:setOption( 3, 'CURRENT_USER\MY\'+cCN ) oServerWS:open('POST', linkWS, .F.) oServerWS:setRequestHeader('SOAPAction', cSOAPAction ) oServerWS:setRequestHeader('Content-Type','application/soap+xml; charset=utf-8') oServerWS:send(oDOMDoc:xml) Grato por algum idéia Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.