Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Encryption of a string that's greater than 215

Posted on by 29
Hello. 

I am currently engaged in developing an extension for Business Central cloud runtime 10.0.
My objective is to ensure the security of sensitive customer data by encrypting it before transmitting it to an Azure Function. The function will then decrypt it and further encrypt it with PGP, as mandated by business requirements.

Prior to transmitting this sensitive data, I aim to encrypt it to maintain its security throughout the HTTP request process.

However, I've encountered a limitation with System.Encrypt, which is restricted to text[215], whereas the data I need to encrypt exceeds 10k characters.

I am seeking suggestions on how to do this without resorting to uploading the text to blob storage and retrieving it through an Azure Function.

Alternatively, if there is a method to perform PGP encryption within Business Central, that would also be a viable solution. However, since it's not an on-premise setup, utilizing .NET DLLs isn't doable, and I'd likely need to develop a custom implementation.

Any insights or recommendations would be greatly appreciated.
Categories:
  • M(-12060832-0 Profile Picture
    M(-12060832-0 29 on at
    Encryption of a string that's greater than 215
    I semi figured out a way to get around the encryption limit of 215
     
    for i := 1 to StrLen(myTextToEncrypt) do begin
                if i = 215 then begin
                    tempStringList.Add(tempString);
                    tempString:= '';
                    i := 1;
                end
                else begin
                    if myTextToEncrypt= '' then begin
                        tempStringList.Add(tempString);
                        break;
                    end;
                    tempString+= myTextToEncrypt[1];
                    myTextToEncrypt:= DelStr(myTextToEncrypt, 1, 1)
                end;
     
            end;
            for i := 1 to tempStringList.Count do begin
                tempString:= EncryptText(tempStringList.Get(i));
                secondListOfText.Add(tempString);
            end;
            for i := 1 to secondListOfText.Count do begin
                tempvar2 := Decrypt(secondListOfText.Get(i));
                finalListOfStrings.Add(tempString);
            end;

    So what I did was split the original string up into lists of text[215] and by adding 1 char at a time to the new entry and then deleting that char
    from the original text, I'd end up with my original string seperated into X amount of text[215].
    Each iteration I think if the original string is empty to make sure that even if remaining text is less than 215 chars, 
    it will still complete and not alter the text.

    All that you'd have to do then was run through the list and encrypt each of them. They do however need to kept seperated until
    ​​​​​​​they've been decrypted again.


    This is an extremely hacky solution, and a desperate one. 
    It did however not work for me because seeing as we are using cloud Business Central I could not export the encryption key and niether do we know
    which encryption was used, so I could not decrypt it in a .net project, as far as I know. 

    Hope this may help someone in the future.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    Encryption of a string that's greater than 215
    Hi, sorry, I haven't tried it, but I think you can try the integration of Azure Function and Logic Apps.
    Decrypt PGP Files Seamlessly with Azure Function and Azure Logic Apps
     
    Use Azure Functions with Dynamics 365 Business Central
     
     
    Hopefully other experts can give you better advice.
    Thanks.
    ZHU

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans