Page 2 of 2
Re: firmar XML
Posted: Mon Sep 09, 2019 10:42 pm
by IMATECH
Here you con find the code to sign a XML file using MS Capicom
https://github.com/JoseQuintas/sefazcla ... assina.prg
Regards
Re: firmar XML
Posted: Sat Sep 14, 2019 4:20 pm
by edufloriv
Hola IMATECH,
Puse a prueba el código que gentilmente me pasaste, desafortunadamente se queda en la siguiente línea:
Code: Select all
BEGIN SEQUENCE WITH __BreakBlock()
cRetorno := "Erro Assinatura: Não carregado MSXML2.MXDigitalSignature.5.0" //<--- ME LANZA ESTE ERROR
#ifdef __XHARBOUR__
xmldsig := xhb_CreateObject( "MSXML2.MXDigitalSignature.5.0" )
#else
xmldsig := win_OleCreateObject( "MSXML2.MXDigitalSignature.5.0" )
#endif
Parece que el problema es una incompatibilidad con Win-10
http://pctoledo.com.br/forum/viewtopic ... &start=15
¿ Hay forma de resolverlo ? - Mil gracias por su valioso tiempo.
-------------------------------------------------------------------------------------------------------------------------------------
Hi IMATECH,
I tested the code you graciously passed me, unfortunately it stays on the following line:
Code: Select all
BEGIN SEQUENCE WITH __BreakBlock()
cRetorno := "Erro Assinatura: Não carregado MSXML2.MXDigitalSignature.5.0" //<--- THROW ME THIS ERROR
#ifdef __XHARBOUR__
xmldsig := xhb_CreateObject( "MSXML2.MXDigitalSignature.5.0" )
#else
xmldsig := win_OleCreateObject( "MSXML2.MXDigitalSignature.5.0" )
#endif
It seems that the problem is an incompatibility with Win-10
http://pctoledo.com.br/forum/viewtopic ... &start=15
Is there a way to solve it? - Thank you for your valuable time.
Re: firmar XML
Posted: Sun Sep 15, 2019 4:42 am
by IMATECH
HI Eduardo !
Looks you don't have "Microsoft XML Core Services 5.0" in your machine (it's part of MS Office 2003)
Are you using "File based Key" or "USB Token" ?
*The sign process can use Open SSL or WinCrypt (no MS Office needed)
MSXML 5.0 MSXML5 is a binary developed specifically for Microsoft Office. It originally shipped with Office 2003 and also ships with Office 2007. Microsoft has not released documentation for this version because Microsoft considers MSXML 5 an internal/integrated component of Office 2003. MSXML 5 is not included in Office 2010.
Re: firmar XML
Posted: Mon Sep 16, 2019 1:22 pm
by edufloriv
Hi Imatech,
I am using file based key, I have got : .CRT, .KEY, .PEM and .PFX files, I have tried with all these formats without result.
I have OpenSSL instaled on my computer. I must sign all the .XML file and these must be the result:
XML before sign:
Code: Select all
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent></ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
XML after sign:
Code: Select all
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent>
<ds:Signature Id="SignIMM">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>IwJuNQGQaHmmm3iv2jj8JDv70Ow=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>
nLaghokzMNrmrfPnbIg9b........wzZ2CgLTVjWQUAQ4wDAYDVQQIEwVNYWluZTE1UiLFwZXXXPUlf2o=
</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data>
<ds:X509Certificate>
MIIFhzCCA3OgAwI......MIIEVDCCAzygAwIBAgIJAPTrkMJbCOr1MA0GCSqGSIb3DQEBBQUAMHkxCzAJBgNVBAYTAlVTVQQIEwVNYWluZTEgMOiRJ00nE=
</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
I would apreciate your help.
Best regards.
Re: firmar XML
Posted: Tue Sep 17, 2019 1:49 am
by IMATECH
HI Eduardo !
Looks you don't have "Microsoft XML Core Services 5.0" in your machine (it's part of MS Office 2003)
Can you install it and make the test again ?
1) ..\SefazClass\hbMk2 sefazclass
2)..\SefazClass\tests\hbMk2 Test -hbwin
3)..\SefazClass\tests\Test.exe
3.1) Option 2 - Seleciona certificado (Select Cert Key)
3.2) Option 18 - Assinatura, arquivo do usuário (Sing a XML)
3.2.1) Select a XML file then you will have a signed one (*changes needed below)
To save XML signed, file test.prg, line 341~
Code: Select all
CASE nOpc == OPC_ASSINA_USUARIO
oSefaz:cXmlDocumento := MemoRead( win_GetOpenFileName(, "Choose a XML file to sign", ".\", "XML", "*.XML", 1 ) )
oSefaz:AssinaXml()
hb_MemoWrit( "Respuesta.txt", oSefaz:cXmlRetorno )
hb_MemoWrit( "SignedFile.xml", oSefaz:cXmlDocumento )
Inkey(0)