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

Announcements

No record found.

News and Announcements icon
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,943

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
    4,009 on at

    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

    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,943 on at

    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,943 on at

    I found System.Security.Cryptography.Xml

    Thanks for inspiring me!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

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

  • Andrey Baludin Profile Picture
    3,943 on at

    It'll be great!

  • Andrey Baludin Profile Picture
    3,943 on at

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

  • Andrey Baludin Profile Picture
    3,943 on at

    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,943 on at

    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

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans