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

Unable to Sign Data Using RS256 Encryption Algorithm with our own Key.

(0) ShareShare
ReportReport
Posted on by 18
Hi,
 
We have a requirement to create JWT Token using RS256 Encryption algorithm with our key on On-Cloud Environment.
We have tried to do this using the Codeunit RSACryptoServiceProvider, but as far as we could understand, it does not provide the option to use our own key, instead, it initializes its own key. 
We are unable to create an instance of RSACryptoServiceProvider with our key. Is there any option to use our key instead of initializing a new one?
Can anyone assist here?
 
Regards
Vishal Mittal
I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    25,078 Most Valuable Professional on at
    Unable to Sign Data Using RS256 Encryption Algorithm with our own Key.
    Hi
    I hope I understood correctly, I hope this can help you or give you some ideas.
    BR
    GR
  • VM-14050617-0 Profile Picture
    18 on at
    Unable to Sign Data Using RS256 Encryption Algorithm with our own Key.
    Hi @gdrenteria
     
    Thank you for your quick response. I forgot to mention that we are doing it On-Cloud environment. Solution suggested by you will work only for On-Prem environment.
     
    Regards
    Vishal Mittal
     
  • VP-26091629-0 Profile Picture
    4 on at
    Unable to Sign Data Using RS256 Encryption Algorithm with our own Key.
    I am running this test code and it is causing the session to crash. Is it known bug?
     
     
    pageextension 70100 CustomerListExt extends "Customer List"
    {
        actions
        {
            addlast(Processing)
            {
                action(RSATest)
                {
                    ApplicationArea = All;
     
                    trigger OnAction()
                    var
                        RSAKey: Text;
                    begin
                        RSAKey := '<RSAKeyValue><Modulus>secrettext</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>AwIDAQAB</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>';
                        Message(RSAEncrypt('TestTextToEncrypt', RSAKey));
                    end;
                }
     
            }
        }
     
        procedure RSAEncrypt(TextToEncrypt: Text; RsaXmlKey: SecretText): Text
        var
            RSACryptoProvider: Codeunit RSACryptoServiceProvider;
            Base64Convert: Codeunit "Base64 Convert";
            TempBlob: Codeunit "Temp Blob";
            PlainTextOutStream: OutStream;
            EncryptedTextInStream: InStream;
            EncryptedTextOutStream: OutStream;
            EncryptedTextBase64: Text;
        begin
            // Convert the text to an OutStream
            TempBlob.CreateOutStream(PlainTextOutStream, TEXTENCODING::UTF8);
            PlainTextOutStream.WriteText(TextToEncrypt);
     
            // Reset the TempBlob and prepare InStream for encryption
            TempBlob.CreateInStream(EncryptedTextInStream, TEXTENCODING::UTF8);
     
            // Prepare OutStream for receiving encrypted data
            TempBlob.CreateOutStream(EncryptedTextOutStream);
     
            // Encrypt the text
            RSACryptoProvider.Encrypt(RsaXmlKey, EncryptedTextInStream, true, EncryptedTextOutStream);
     
            // Reset the TempBlob and create an InStream to read the encrypted data
            TempBlob.CreateInStream(EncryptedTextInStream);
     
            // Convert the encrypted data to Base64
            EncryptedTextBase64 := Base64Convert.ToBase64(EncryptedTextInStream);
     
            exit(EncryptedTextBase64);
        end;
    }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans