Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

wrong insertion of Base 64 data insertion into sql nvarchar field

Posted on by 6
I have a field to encrypt in FO, I have encrypted the value and tried to insert it into SQL, but the actual value inserted is different from the actual encrypted value.
is there some specific method to insert the base 64 string?

For example a particular string I got the encrypted value as /xTIEbaHkxRnZVfg6U02vYg==/ but /w1vy4s5am604pog6e+n2vqg2fyo=/ is what I can find in the backend SQL.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    wrong insertion of Base 64 data insertion into sql nvarchar field
    Maybe I see the problem. If it's a US company, the value returned by encrypt() isn't what is sent to database, because update() method changes the value (this.Tax1099RegNum = Tax1099ElectronicCheck::formatTIN(this.Tax1099RegNum, this.TaxIDType)).
  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    wrong insertion of Base 64 data insertion into sql nvarchar field
    Let's change your test case a little bit:
    ttsbegin;
    
    select firstOnly forUpdate vendTable
        where vendTable.AccountNum = '001';
    
    vendTable.Tax1099RegNum = EncryptDecrypt::encrypt(vendtable.Tax1099RegNum, int2Str(tableNum(VendTable)));
    vendTable.doUpdate();

    info(strFmt("RecId: %1, value %2", vendTable.RecId, vendTable.Tax1099RegNum)); ttscommit;
    Then find the record in DB by RecId  and compare the value of Tax1099RgNum field. What is the result?
     
    I'll be easier than dealing with several records at once, we check actual the value of the field.
  • wrong insertion of Base 64 data insertion into sql nvarchar field
    I have used the runnable class for the testing purpose of this task, I tried to print the value on screen using info fn. and then updated the existing value in the table.
    in this scenario I am getting different values on my info statement and SQL

    my code like like this in a runnable class
     
     select forupdate vendtable where vendtable.AccountNum = '001'
            {
                str encStr;
                encStr = EncryptDecrypt::encrypt(vendtable.Tax1099RegNum,int2Str(tableNum(VendTable)));
                Info(encStr); 
                ttsbegin
                vendtable.Tax1099RegNum = encryptDecrypt::encrypt(vendtable.Tax1099RegNum,int2Str(tableNum(VendTable)));
                vendtable.update();
                ttscommit; 
            }
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,188 Super User 2024 Season 2 on at
    wrong insertion of Base 64 data insertion into sql nvarchar field
    Hi,
     
    Can you share the coding you wrote, so we can verify what might be wrong here?
  • Martin Dráb Profile Picture
    Martin Dráb 230,030 Most Valuable Professional on at
    wrong insertion of Base 64 data insertion into sql nvarchar field
    You must have something wrong in your code, because the database wouldn't change the string to another one (unless there was a trigger, but in the case of F&O, almost all logic is in the application layer).
     
    By the way, why do you use base64 at all? It consumes more disk space and processing power than storing binary data directly.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans