Skip to main content

Notifications

Announcements

No record found.

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

  • VM-14050617-0 Profile Picture
    VM-14050617-0 6 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
  • Techworld Profile Picture
    Techworld 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

  • Suggested answer
    Marco Mels Profile Picture
    Marco Mels 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

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans