How to add digital signature to xml file?

arcullarcull Member Posts: 191
Hi everyone. I wonder if someone has some experiences with adding digital signature to xml files. What I want to do is, to sign the xml document with digital certificate (pfx file) installed on local machine. I saw xml dom 5 library has some of the required methods to do the signing, but I just can't figure out how to use it properly, so any suggestion is highly appreciated, thanks.

Comments

  • klhaklha Member Posts: 5
    I found Dan's Blog helpful: http://www.danlance.co.uk/index.cfm/201 ... ation-Wind

    After installing the certificate you can try something like this in Navision:

    WinHTTPReq: Automation 'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest
    WebserviceEndpoint: Text
    ClientCertificate: Text
    TheXML: Text or a DOMDocument

    WebserviceEndpoint := 'https://myWebserviceEndpoint';
    ClientCertificate := 'LOCAL_MACHINE\My\TheCertificatesSubjectCN';
    CREATE(WinHTTPReq);
    WinHTTPReq.Open('POST',WebserviceEndpoint,FALSE);
    WinHTTPReq.SetClientCertificate(ClientCertificate);
    WinHTTPReq.Send(TheXML);


    Good luck!
    Klaus
  • arcullarcull Member Posts: 191
    Thank you very much Klaus for the info. But unfortunately this approach requires to use a web service (remote or local), is it possible to avoid this requirement? If you had similar situation, would you be so kind to explain a bit more in detail how you solved this issue, thanks again.
  • arcullarcull Member Posts: 191
    I guess I'll have to do the signature part in C#. Thanks anyway for your help.
  • IsakssonMiIsakssonMi Member Posts: 77
    Hi!

    You only need to know which elements you want to use in your signature block.

    Then you could use the MSXML automations and build it. You don't need .NET for that.

    Check out: http://www.w3.org/TR/xmldsig-core/
  • arcullarcull Member Posts: 191
    Hi!

    You only need to know which elements you want to use in your signature block.

    Then you could use the MSXML automations and build it. You don't need .NET for that.

    Check out: http://www.w3.org/TR/xmldsig-core/

    well actually it is not that simple :) for the start, you need to be able to get access to X509Store which holds digital signatures installed on LocalMachine or CurrentUser, afterwards you need X509Certificate2 class to actually address the stored certificate rings. And when you find the correct one, you need to verify it has private key to be able to use it for signing. Then you must compute the signature and add a new xml node containing it in the correct place. Ok, this was pretty simplified described, but you need to know that it is not just assembling of xml elements to a file, but rather a bit more complicated procedure. If you know how to code all this via C/AL using correct automations (if available at all) , I'll buy you a beer :)
Sign In or Register to comment.