Page 1 of 2

XML Signature

Posted: Sun Jun 18, 2023 1:24 pm
by Diego Euri Almanzar
Hello everyone!

Maybe I'm wrong, but after studying the case for a long time, I notice that xmlsec is actually libxml2. And, there's no way to install it for Xbase++, it doesn't have an ocx installer.

As libxml2 is a C language library, and it doesn't have an ocx, I tried to read it with the following, but it didn't work.

nDll := DllLoad( "libxml2.DLL")

However, in Python they use it very simply as the following:

import libxml2


Obviously, it's just an example, because I don't use python.
I am no longer interested in validating an XML via an XSD. I already got that with another library.
What I need now is a library to sign the XML. As you know, an electronic invoice needs the XML to be signed.

From my point of view libxml2 is the most powerful thing that exists for handling XML.
C# developers, and .NET developers, have modified their sources and have very good adaptations, and very easy to use.

But, as I said before, my interest is in Xbase++

If someone can help me find a library to sign an XML, even with SOAP technology, I'll appreciate it.

Re: XML Signature

Posted: Sun Jun 18, 2023 4:39 pm
by Auge_Ohr
hi Diego,

like *.OCX you mus "register" external *.DLL before you can use it
this will normal done by Installer

general it is hard to find Source for Xbase++ and most you must build a "Wrapper" to use it with Xbase++

it is much more easy when use BCC, MSVC or MinGW Compiler with "C" CODE under harbour (HMG, MiniGUI, Fivewin)

Re: XML Signature

Posted: Sun Jun 18, 2023 8:06 pm
by Diego Euri Almanzar
From what I can interpret, MinGW is a port of Linux (GNU, actually) tools for Windows, including a port of GCC (the actual compiler). MSVC, on the other hand, is a native Windows runtime and toolchain for creating C/C++ executables.

Actually, I'm looking for something more practical. An Ocx that is already done.

Chilkat, could be my solution. It costs 300 dollars. There are many Chilkat components that are free. But, that of the digital signature, it is not.

I haven't avoided Chikat over the $300 thing. I just wanted to find another more robust solution. I'm afraid that when buying Chilkat, errors start due to digital certificates, as happens with many of those Internet librarys.

In the end, one invests a lot of money, without obtaining the solution.

As I said before, I would have liked to use libxml2. But, I can't find the way to integrate it to Xbase++

Thank you very much, Jimmy.

Re: XML Signature

Posted: Sun Jun 18, 2023 9:58 pm
by Auge_Ohr
hi Diego,

Xbase++ User most does not work with Windows API or "C" CODE which is different to "Open-Source" Community

Ot4xb, made by Pablo Botella, was my Way to get into Windows APT World
https://blog.xbwin.com/
you can ask Pablo if he have a Sample how use a XML-Signature with Xbase++ and Ot4xb

you also can ask in Fivewin Forum to get some Idea.
https://forums.fivetechsupport.com
but this is harbour World where you can get almost everything as "Open-Source" CODE

Re: XML Signature

Posted: Mon Jun 19, 2023 12:16 am
by Tom
like *.OCX you mus "register" external *.DLL before you can use it
This is not true for all DLLs. If a DLL is used as a container for ActiveX-comonents, it's true, but if a DLL publishes functions using other calling conventions, there is no registration needed.

Re: XML Signature

Posted: Mon Jun 19, 2023 9:23 am
by Diego Euri Almanzar
Hi jimmy

Completely agree with you. Xbase++ has limitations to access C language libraries.
I will enter the forums that you indicate, and I will ask the questions.

Thank you.




Hello Tom

Using Regsvr32 in Windows to register a dll is like a mystery or horror movie. In 99% of cases it doesn't work. And, if it manages to register, I wouldn't know what to name the Ocx to create the object.

The same name of the dll library? Could be. But, generally, ocx do not behave that way. It would definitely be an adventure.

Thank you.

Re: XML Signature

Posted: Mon Jun 19, 2023 10:33 pm
by Tom
Hi, Diego.

In case you have to deliver an ActiveX control with your app, using REGSVR32 is not the only way to ensure the controls are registered. You can embed all information in the manifest file you link to your app. We had that here in the forum several times; just look for "manifest".

The docs about the control or library should mention which IDs should be used adressing the functions. If you look at the excellent Chilkat documentation, you easily find out how the library is unlocked for use and how the different wrapping objects are created. This is no magic.

Re: XML Signature

Posted: Tue Jun 20, 2023 1:21 am
by Diego Euri Almanzar
Hello Tom

Totally agree, with Chilkat everything is clear, everything is excellent. For example:

(FoxPro)
loObject = CreateObject('Chilkat_9_5_0.XmlDSigGen')

However, I wanted to have a second option, before deciding to buy the Chilkat. Also, if it's free it's much better. Because when it comes to protocols that involve certificates, things tend to get complicated.

And since C, C#, .Net, etc. use the libxml2.dll library, I wanted to have a second option. I tried to register the library with REGSVR32, but it always said that it couldn't find the library. Copy the library to system32, when the operating system is 32 bits, and it didn't work. I have also tried 64 bit. I have also tried copying the library to the same folder as the application, it hasn't worked either.

But this inconvenience of registering a library has not only happened to me with libxml2.dll It has also happened to me when I wanted to use XbpRtf() is a wrapper class for the Microsoft RTF ActiveX control. Because it is a Microsoft Active X, I thought the matter would be simple, but I have not been able to use it. The supposed ocx to allow the use of Xbprtf() is never installed.

But, the libxml2.dll issue is even worse, because it doesn't have ocx. And, if REGSVR32 inclusion is achieved, there is no method description to declare the object. Chilkat, if you have your tags to declare the object, for example: "Chilkat_9_5_0.XmlDSigGen"

While it's true that Chilkat is versatile and without mystery, let me give you an example of how easy it is to sign an XML with libxml2, in the C# language:

sing System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Xml;

// Create a new RSA signing key and save it in the container.
RSACryptoServiceProvider rsaKey = new(cspParams);

// Create a new XML document.
XmlDocument xmlDoc = new()
{
// Load an XML file into the XmlDocument object.
PreserveWhitespace = true
};
xmlDoc.Load("test.xml");

// Sign the XML document.
SignXml(xmlDoc, rsaKey);

Console.WriteLine("XML file signed.");

// Save the document.
xmlDoc.Save("test.xml");


The original XML document is invoked. Then it is signed. And finally, you get a new signed XML document. This is even clearer than Chilkat. Or at least, clearer for me, that it is easier for me to understand this nomenclature. But, I haven't been able to declare the libxml2 library yet, nor would I know how to declare their respective objects or functions.

Thank you very much for the help.

Re: XML Signature

Posted: Tue Jun 20, 2023 1:37 am
by Tom
Hi, Diego.

If you can't register LIBXML2.DLL with REGSVR32, although it's in your path and you're working as an administrator, maybe there are files missing needed by the library. Since I can't find a reliable source to download it from, I can't tell you which files are needed in addition. Some controls coming as DLLs (or .OCX or whatever) need additional files. If you get an error code from REGSVR32, search the web for the code displayed.

Re: XML Signature

Posted: Wed Jun 21, 2023 7:46 am
by SlavkoDam
Hi Diego,

My PowerCrp library for cryptography has functions for signing and verifying all kinds of data and documents. Its a Xpp solution, no OCX is need, very simple to use. Just one simple function call, no monkey work with ActiveX object and its methods and properties.

After you load a dll with nDll := DllLoad( "libxml2.DLL"), you have to call DllCall() to execute a function from the library. To list all functions in a library you can use some dll export tool, which you can find on the Internet.

It is not true that XbpRtf() don't work. There is an example in Alaska ActiveX samples with XbpRtf(). You can study it and learn how to use it. Rtf ActiveX control is installed by default by Windows and it doesn't need any OCX.