Skip to main content
Post a question

Notifications

Community site session details

Community site session details

Session Id : M7xcZDcg/yJAU9kR4mpGbd
Microsoft Dynamics NAV (Archived)

Signature for XML file

Like (0) ShareShare
ReportReport
Posted on 7 Jun 2018 08:52:09 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

  • JJMc Profile Picture
    291 on 11 Dec 2022 at 10:40:17
    RE: Signature for XML file

    A question.

    And how or where are you setting the certificate and password to sign the document?

    Thank you ever so much

  • Andrey Baludin Profile Picture
    3,941 on 14 Jun 2018 at 14:45:13
    RE: Signature for XML file

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

    RSA DotNet System.Security.Cryptography.RSACryptoServiceProvider.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    XmlDocument DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    XmlTextReader DotNet System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    SignedXml DotNet System.Security.Cryptography.Xml.SignedXml.'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Reference DotNet System.Security.Cryptography.Xml.Reference.'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    Env DotNet System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform.'System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

    XmlDigSignature DotNet System.Xml.XmlElement.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

  • GreatScott001 Profile Picture
    115 on 14 Jun 2018 at 09:43:59
    RE: Signature for XML file

    Can you list variable types?

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on 11 Jun 2018 at 06:56:36
    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.

  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on 09 Jun 2018 at 15:47:54
    RE: Signature for XML file

    And the answer is:

    1. CSPParams := CSPParams.CspParameters(1, 'Microsoft Base Cryptographic Provider v1.0', 'DevRootCA');
    2.  
    3. RSA := RSA.RSACryptoServiceProvider(CSPParams);
    4.  
    5. XmlDocument := XmlDocument.XmlDocument;
    6. XmlDocument.PreserveWhitespace(FALSE);
    7. XmlDocument.Load(XmlTextReader.XmlTextReader('C:\Temp\Data.xml'));
    8.  
    9. SignedXml := SignedXml.SignedXml(XmlDocument);
    10. SignedXml.SigningKey := RSA;
    11.  
    12. Reference := Reference.Reference;
    13. Reference.Uri := '';
    14.  
    15. Env := Env.XmlDsigEnvelopedSignatureTransform;
    16. Reference.AddTransform(Env);
    17.  
    18. SignedXml.AddReference(Reference);
    19.  
    20. SignedXml.ComputeSignature;
    21. XmlDigSignature := SignedXml.GetXml;
    22. MESSAGE(XmlDigSignature.InnerXml);


  • Andrey Baludin Profile Picture
    3,941 on 09 Jun 2018 at 13:12:54
    RE: Signature for XML file

    So now i have next code:

    1. CSPParams := CSPParams.CspParameters;
    2.  
    3. // Here is main issue ->
    4. //CSPParams.KeyContainerName = 'DevRootCA';
    5. //<-
    6.  
    7. RSA := RSA.RSACryptoServiceProvider(CSPParams);
    8.  
    9. XmlDocument := XmlDocument.XmlDocument;
    10. XmlDocument.PreserveWhitespace(FALSE);
    11. XmlDocument.Load(XmlTextReader.XmlTextReader('C:\Temp\Data.xml'));
    12.  
    13. SignedXml := SignedXml.SignedXml(XmlDocument);
    14. SignedXml.SigningKey(RSA);
    15.  
    16. Reference := Reference.Reference;
    17. Reference.Uri := '';
    18.  
    19. Env := Env.XmlDsigEnvelopedSignatureTransform;
    20. Reference.AddTransform(Env);
    21.  
    22. SignedXml.AddReference(Reference);
    23.  
    24. SignedXml.ComputeSignature;
    25. XmlDigSignature := SignedXml.GetXml;
    26. 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

  • Andrey Baludin Profile Picture
    3,941 on 08 Jun 2018 at 07:35:24
    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 07 Jun 2018 at 10:08:56
    RE: Signature for XML file

    It'll be great!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on 07 Jun 2018 at 09:46:06
    RE: Signature for XML file

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

  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on 07 Jun 2018 at 09:43:40
    RE: Signature for XML file

    I found System.Security.Cryptography.Xml

    Thanks for inspiring me!

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,120 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading started