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 :
Small and medium business | Business Central, N...
Suggested answer

how-can-i-sign-a-file-using-rsa-and-sha256-with-AL

(0) ShareShare
ReportReport
Posted on by 106

Hello Everyone,

I am working with a task where we need to sign data by using private key received from Azure Vault.

Here we are able to do it by following this blog:

How To Access Azure Key Vault Secrets Through Rest API Using Postman (c-sharpcorner.com)

after having this key in system we are trying to use codunit cryptography or RSA 

  CryptoMgmt: Codeunit "Cryptography Management";
        
        rsa: Codeunit RSACryptoServiceProvider;
                SecretKey := 'MIICXgIBAAKBgQDIYh3tSlmpU7rxPepe+c20abLXiYpI1NfxlKh9OThouEble9ir3ymDq4H/OuKsw6yZ21QFYvuE1U7vrwqECb1lmOY4EqdcsmxgKvoZVOcHgB3Bj4DiSl6yGbOE6wwoJbUXlO39eKBRYGBGdg1POEr2ivDPph0XvSk+y+7sZ3ZF1QIDAQABAoGAYtkL3EdmDYJxYJnjaLCfydSuVWbS4XSlhdWIfCVi7z2gM4oxay9t4jcTrJ0WvpTUKx2nx/R5EKDNDK1zaYkIdRs+ASDSI4UuJ9XDLjB3ei9HnNP83ZzSoZ3LYHGNvuqM8ZSk9dJmb7+wuJocScOOnh8LI2GEjYd48SrPxQpXiEECQQDoO5304nUH1ZAuGWel5AER0F9Zg2XEA8carN3AQ4fjX+dKCSgWlYxjMtwjXpN0FL0ohTbvmvJgO3E9XLgdvQYFAkEA3OQObQYw5RokYHg7gmq+20+nyWm2gdbxfG7FyfIfpKCWoLIGMLcTprXr6Xgap/aTvPuuBknmXM5wtqPAxU/5kQJBAJDA6FpF9ZCmi7JQX4zFq+0Apw5SmtItUKPN8ILxFPijRLWfM3+wQ8tpXlIll1+ZtbZWIsIDIOTe6FzJOHJA6kkCQQDOpozYcnJL46kkl1cVK8hiZKMUS1HzJqPFRdzEkUAJRDOnIuWnrZ801/1c7oABoy2UH+EvAPQC3x+Tvp8Z+TgBAkEAySwRR2zFCcQFUYje26G60tyzcd1yKDBau3OOyxC/h1emBWoJtz+VC2nuA3gxBgwSq3sH2jJ2+WEHtolGLz3sCQ==';
                Message(SecretKey);
                //  SecretKey := Base64.ToBase64(SecretKey);
                // SecretKey := '<RSAKeyValue><Modulus>' + SecretKey + '</RSAKeyValue>';//'</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>';
                SIGNATURERECORD.DeleteAll();
                SIGNATURERECORD.Init();
                SIGNATURERECORD."Key Index" := 1;
                SIGNATURERECORD.FromXmlString(SecretKey);
                //    SIGNATURERECORD.ToXmlString(true);
                SIGNATURERECORD.Insert();

                TempBLOB.CreateOutStream(OUTSTREAM1, TextEncoding::UTF8);
                                                     //  OUTSTREAM1.WriteText('2019-01-11;2019-01-11T11:27:08;FAC 001/9;1200.00');
                OUTSTREAM1.WriteText('FAC11');
                TempBLOB.CreateInStream(stream);
                // rsa.ToXmlString(true);
                rsa.SignData(SecretKey, stream, Algo::SHA256, outstream);
                //CryptoMgmt.SignData('FAC11', SIGNATURERECORD, Algo::SHA1, outstream);
                outstream.WriteText(hASHVALUE);
                SIGNATURERECORD.Delete();
Have written this code also to check but runs in issue:
pastedimage1632404580077v1.png
I chekced there is no space in key and it is hardcoded without any space. But facing this issue

I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: how-can-i-sign-a-file-using-rsa-and-sha256-with-AL

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks

  • Techworld Profile Picture
    106 on at
    RE: how-can-i-sign-a-file-using-rsa-and-sha256-with-AL

    Much appreciated. Tried to open in Github also but closed by admin there as they do not take questions in Github

  • VM-14050617-0 Profile Picture
    18 on at
    how-can-i-sign-a-file-using-rsa-and-sha256-with-AL
    Hi,
     
    I am stuck in same kind of scenario. Did you get any solution of this problem?
    Below is the link of the problem I posted on community forum.
     
    Regards
    Vishal Mittal
  • MadMax33 Profile Picture
    18 on at
    how-can-i-sign-a-file-using-rsa-and-sha256-with-AL
    Hi Any solution for this issue?
    I also get this error message
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    19,973 Super User 2025 Season 2 on at

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,214

#2
Sumit Singh Profile Picture

Sumit Singh 2,145

#3
YUN ZHU Profile Picture

YUN ZHU 1,887 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans