web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Signature for XML file

(0) ShareShare
ReportReport
Posted on by 3,941

Hello Team. I really stuck in a rut with next problem:

  1. I generate XML file from NAV 2018.(web request)
  2. I have *.crt and *cer files (signed certificate)
  3. I need to generate signature for XML file using *.cer or *.crt file and I have no idea how to do it using NAV.

I even agree to use C/AL and dotnet variables in NAV2018 instead of AL and extensions if there is any way to generate signature (because i suppose that it's impossible to do without dotnet).

Any help will be appreciate.

*This post is locked for comments

I have the same question (0)
  • Olister Rumao Profile Picture
    3,967 on at
    RE: Signature for XML file

    Hi Andrey,
     Why don't you use Azure Functions and call it from the NAV side

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Signature for XML file

    Without using DotNet I think it's actually not possible. Personally for a task like that I've created a DotNet addin that I'm using from NAV.

  • Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    Is it possible for somebody to share .net code? Or show a libraries which can be used for this task?

  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    I found System.Security.Cryptography.Xml

    Thanks for inspiring me!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Signature for XML file

    Yes if you want I can share it. I've only to return at my office for doing that :)

  • Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    It'll be great!

  • Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    Stefano Demiliani have you had a chance to look for code? I'll be very appreciate.

  • Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    So now i have next code:

    CSPParams := CSPParams.CspParameters;
    
    // Here is main issue ->
    //CSPParams.KeyContainerName = 'DevRootCA';
    //<-
    
    RSA := RSA.RSACryptoServiceProvider(CSPParams);
    
    XmlDocument := XmlDocument.XmlDocument;
    XmlDocument.PreserveWhitespace(FALSE);
    XmlDocument.Load(XmlTextReader.XmlTextReader('C:\Temp\Data.xml'));
    
    SignedXml := SignedXml.SignedXml(XmlDocument);
    SignedXml.SigningKey(RSA);
    
    Reference := Reference.Reference;
    Reference.Uri := '';
    
    Env := Env.XmlDsigEnvelopedSignatureTransform;
    Reference.AddTransform(Env);
    
    SignedXml.AddReference(Reference);
    
    SignedXml.ComputeSignature;
    XmlDigSignature := SignedXml.GetXml;
    MESSAGE(XmlDigSignature.InnerXml);


    I Have dotnet variable CSPParams which I took from mscorlib:

    System.Security.Cryptography.CspParameters.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    And the problem is that it doesn't have .KeyContainerName field. So I can't set it and get the key. As I understood - I just need to set SSL certificate name there? Has anyone encountered a similar problem?

    I'm moving through next instruction:

    docs.microsoft.com/.../how-to-sign-xml-documents-with-digital-signatures

  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at
    RE: Signature for XML file

    And the answer is:

    CSPParams := CSPParams.CspParameters(1, 'Microsoft Base Cryptographic Provider v1.0', 'DevRootCA');
    
    RSA := RSA.RSACryptoServiceProvider(CSPParams);
    
    XmlDocument := XmlDocument.XmlDocument;
    XmlDocument.PreserveWhitespace(FALSE);
    XmlDocument.Load(XmlTextReader.XmlTextReader('C:\Temp\Data.xml'));
    
    SignedXml := SignedXml.SignedXml(XmlDocument);
    SignedXml.SigningKey := RSA;
    
    Reference := Reference.Reference;
    Reference.Uri := '';
    
    Env := Env.XmlDsigEnvelopedSignatureTransform;
    Reference.AddTransform(Env);
    
    SignedXml.AddReference(Reference);
    
    SignedXml.ComputeSignature;
    XmlDigSignature := SignedXml.GetXml;
    MESSAGE(XmlDigSignature.InnerXml);


  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Signature for XML file

    Hi Andrey, I've checked and my addin performs criptography with signed certificate (with RSACryptoServiceProvider).

    I think this is not exactly what you was searching. Nice to see that you've solved your problem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Alexander Ermakov Profile Picture

Alexander Ermakov 2

#2
SC666 Profile Picture

SC666 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans