<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi, can you help me?<br>The xml file:<br><?xml version="1.0"?><br><!DOCTYPE test [<!ATTLIST infNFe Id ID #IMPLIED>]><br><NFe xmlns="http://www.portalfiscal.inf.br/nfe"><infNFe versao="2.00" Id="NFe52120503241828000120550020000067501112798840"><br>..........<br></infNFe><br><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><br>  <SignedInfo><br>    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><br>    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><br>    <Reference URI="#NFe52120503241828000120550020000067501112798840"><br>      <Transforms><br>        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><br>        <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><br>      </Transforms><br>      <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><br>      <DigestValue/><br>    </Reference><br>  </SignedInfo><br>  <SignatureValue/><br>  <KeyInfo><br>    <X509Data><br>      <X509Certificate/><br>    </X509Data><br>  </KeyInfo><br></Signature></NFe><br><br>With command line tool:<br>xmlsec --sign --print-debug --output nfe_sign.xml --pkcs12 sos.p12 --pwd XXXXXXXX nfe3.xml<br>All Works.<br><br>= SIGNATURE CONTEXT<br>== Status: succeeded<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== Key Info Read Ctx:<br>= KEY INFO READ CONTEXT<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled key data: all<br>== RetrievalMethod level (cur/max): 0/1<br>== TRANSFORMS CTX (status=0)<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled transforms: all<br>=== uri: NULL<br>=== uri xpointer expr: NULL<br>== EncryptedKey level (cur/max): 0/1<br>=== KeyReq:<br>==== keyId: rsa<br>==== keyType: 0x00000002<br>==== keyUsage: 0x00000001<br>==== keyBitsSize: 0<br>=== list size: 0<br>== Key Info Write Ctx:<br>= KEY INFO WRITE CONTEXT<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled key data: all<br>== RetrievalMethod level (cur/max): 0/1<br>== TRANSFORMS CTX (status=0)<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled transforms: all<br>=== uri: NULL<br>=== uri xpointer expr: NULL<br>== EncryptedKey level (cur/max): 0/1<br>=== KeyReq:<br>==== keyId: NULL<br>==== keyType: 0x00000001<br>==== keyUsage: 0xffffffff<br>==== keyBitsSize: 0<br>=== list size: 0<br>== Signature Transform Ctx:<br>== TRANSFORMS CTX (status=2)<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled transforms: all<br>=== uri: NULL<br>=== uri xpointer expr: NULL<br>=== Transform: c14n (href=http://www.w3.org/TR/2001/REC-xml-c14n-20010315)<br>=== Transform: rsa-sha1 (href=http://www.w3.org/2000/09/xmldsig#rsa-sha1)<br>=== Transform: base64 (href=http://www.w3.org/2000/09/xmldsig#base64)<br>=== Transform: membuf-transform (href=NULL)<br>== Signature Method:<br>=== Transform: rsa-sha1 (href=http://www.w3.org/2000/09/xmldsig#rsa-sha1)<br>== Signature Key:<br>== KEY<br>=== method: RSAKeyValue<br>=== key type: Private<br>=== key usage: -1<br>=== rsa key: size = 2048<br>=== list size: 1<br>=== X509 Data:<br>==== Key Certificate:<br>==== Subject Name: /C=BR/O=ICP-Brasil/OU=Secretaria da Receita Federal do Brasil - RFB/OU=CORREIOS/OU=ARCORREIOS/OU=RFB e-CNPJ A1/L=GOIANIA/ST=GO/CN=S O S COMERCIO DE MAQUINAS LTDA ME:01800246000100<br>==== Issuer Name: /C=BR/O=ICP-Brasil/OU=Secretaria da Receita Federal do Brasil - RFB/CN=Autoridade Certificadora do SERPRORFB<br>==== Issuer Serial: 32303131303931323139303131363337<br>==== Certificate:<br>==== Subject Name: /C=BR/O=ICP-Brasil/OU=Secretaria da Receita Federal do Brasil - RFB/OU=CORREIOS/OU=ARCORREIOS/OU=RFB e-CNPJ A1/L=GOIANIA/ST=GO/CN=S O S COMERCIO DE MAQUINAS LTDA ME:01800246000100<br>==== Issuer Name: /C=BR/O=ICP-Brasil/OU=Secretaria da Receita Federal do Brasil - RFB/CN=Autoridade Certificadora do SERPRORFB<br>==== Issuer Serial: 32303131303931323139303131363337<br>== SignedInfo References List:<br>=== list size: 1<br>= REFERENCE CALCULATION CONTEXT<br>== Status: succeeded<br>== URI: "#NFe52120503241828000120550020000067501112798840"<br>== Reference Transform Ctx:<br>== TRANSFORMS CTX (status=2)<br>== flags: 0x00000000<br>== flags2: 0x00000000<br>== enabled transforms: all<br>=== uri:<br>=== uri xpointer expr: #NFe52120503241828000120550020000067501112798840<br>=== Transform: xpointer (href=http://www.w3.org/2001/04/xmldsig-more/xptr)<br>=== Transform: enveloped-signature (href=http://www.w3.org/2000/09/xmldsig#enveloped-signature)<br>=== Transform: c14n (href=http://www.w3.org/TR/2001/REC-xml-c14n-20010315)<br>=== Transform: sha1 (href=http://www.w3.org/2000/09/xmldsig#sha1)<br>=== Transform: base64 (href=http://www.w3.org/2000/09/xmldsig#base64)<br>=== Transform: membuf-transform (href=NULL)<br>== Digest Method:<br>=== Transform: sha1 (href=http://www.w3.org/2000/09/xmldsig#sha1)<br>== Result - start buffer:<br>hn6gfGRWNBeR+CE6QQEU01E8e6A=<br>== Result - end buffer<br>== Manifest References List:<br>=== list size: 0<br>== Result - start buffer:<br>c3hAUplnTN5WuP4nSW327q20JEiKjWj/p9tLY9thHw9RoUJcj/TDkG2zEZUn219i<br>vax5RMDmfk7T3HuBqg2xtEe6TxBRBlcECeQJz6BGj2xfbwLRqBAfR9gDEha+qpXu<br>7aJvvxCBps8szV2je1ThWPXSZx274NYz5uDdnGv+h6bVBbb30aMqK+/mUlwe4/Bp<br>y58RKdoQC7RVQ4S3qiZ1cKGrfoPdhN73qsDjJhVub2a152n8qDwzEbM+ajUhX7Aa<br>BC99E3On9goJ7T0uz+RuHgLptRhrdaSQTZOl5pRgvFPKOfKeyX6svVHU3Kly+Q6t<br>Zx/edQpvMu8lp63lqa/u5g==<br>== Result - end buffer<br><br>But the same file: nfe3.xml with:<br>xml_sign(const char *tmpl_file, const char *key_file, const char *password1)<br>{<br>    xmlDocPtr doc = NULL;<br>    xmlNodePtr node = NULL;<br>    xmlSecDSigCtxPtr dsigCtx = NULL;<br><br>    /* load template */<br>    doc = xmlParseFile(tmpl_file);<br>    if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL))<br>    {<br>       fprintf(stderr, "Error: unable to parse file \"%s\"\n", tmpl_file);<br>       goto done;     <br>    }<br>   <br>    /* find start node */<br>    node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);<br>    if (node == NULL)<br>    {<br>          fprintf(stderr, "Error: start node not found in \"%s\"\n", tmpl_file);<br>          goto done;<br>    }<br><br>    /* create signature context, we don't need keys manager in this example */<br>    dsigCtx = xmlSecDSigCtxCreate(NULL);<br>    if (dsigCtx == NULL)<br>    {<br>       fprintf(stderr,"Error: failed to create signature context\n");<br>       goto done;<br>    }<br><br>    /* load private key with password */<br>    dsigCtx->signKey = xmlSecCryptoAppKeyLoad(key_file, xmlSecKeyDataFormatPkcs12, password1, NULL, NULL);<br>    if (dsigCtx->signKey == NULL)<br>    {<br>       fprintf(stderr,"Error: failed to load private pem key from \"%s\"\n", key_file);<br>       goto done;<br>    }<br><br>    /* set key name to the file name, this is just an example! */<br>    if (xmlSecKeySetName(dsigCtx->signKey, (xmlChar *) key_file) < 0)<br>    {<br>       fprintf(stderr,"Error: failed to set key name for key from \"%s\"\n", key_file);<br>       goto done;<br>    }<br><br>    /* sign the template */<br>    if (xmlSecDSigCtxSign(dsigCtx, node) < 0)   <---- FAILL<br>    {<br>       fprintf(stderr, xmlSecErrorsGetMsg(xmlSecErrorsGetCode(0)));<br>       goto done;<br>    }<br>}<br><br>Not work! Result:<br><pre>func=xmlSecDSigCtxProcessSignatureNode:file=..\src\xmldsig.c:line=465:ob
j=unknown:subj=dsigCtx->c14nMethod == NULL:error=100:assertion:
func=xmlSecDSigCtxSign:file=..\src\xmldsig.c:line=303:obj=unknown:subj=x
mlSecDSigCtxSigantureProcessNode:error=1:xmlsec library function failed:</pre>Latest dlls from http://www.zlatkovic.com/libxml.en.html<br>xmlsec-1.2.18<br>libxml2-2.7.8<br>openssl-0.8a<br><br>Is necessary a key manager?<br><br>Thanks for your patience.<br>Any help will much appreciate.<br><br>Best regards,<br><br>Ranier Vilela<br>                                          </div></body>
</html>