web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Data Encryption

(0) ShareShare
ReportReport
Posted on by 409

Hi All,

I am trying to encrypt and decrypt a field in a table. I am storing the encrypted  value as a string in the table. I have written a class with encrypt() and decrypt(). The encrypt works fine but when I try to decrypt i get an error

saying  ----------->  "Error occurred while encrypting/decrypting." 

the code in my decrypt method is below.

public static server EncryptedURLParameter decryptString(str _res)
{
CryptoAPI              cryptoAPI;
container              decryptedContainer;
ContainerClass      concls;

cryptoAPI = new CryptoAPI(99999999999);
decryptedContainer = BinData::stringToData(_res);
decryptedContainer = ContainerClass::blob2Container(cryptoAPI.decrypt(decryptedContainer));

return con2Str(decryptedContainer);
}

 

Thanks in advance for the help.

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,443 User Group Leader on at

    I cannot see anywhere 'encrypt' keyword in your code.

    Kindly run code as following

    public static server EncryptedURLParameter decryptString(str _res)
    {
        CryptoAPI              cryptoAPI;
        container              decryptedContainer;
        ContainerClass         concls;
    
            cryptoAPI = new CryptoAPI(99999999999);
            decryptedContainer = BinData::stringToData(_res);
            concls=new ContainerClass([_res]);
        
                    decryptedContainer=cryptoAPI.encrypt(concls.toBlob());//encrypt
        
                    decryptedContainer = ContainerClass::blob2Container(cryptoAPI.decrypt(decryptedContainer));
        
                    info(con2Str(decryptedContainer));//info for test    
        
        return con2Str(decryptedContainer);    
    }
    


  • SKO Profile Picture
    409 on at

    I used your code and tested it in job. It returns the same thing as what I have passed.

    Not sure what i missed. my class is below. Please correct it

    class AVFEncryption

    {    

       container   decCon, con, encCon;

    }

    public static server EncryptedURLParameter encryptString(str _urlParameter)

    {

       CryptoAPI       cryptoAPI;

       ContainerClass  concls;

       container       con, encCon;

       cryptoAPI   = new CryptoAPI(99999999999);

       concls      = new ContainerClass([_urlParameter]);

       encCon      = cryptoAPI.encrypt(concls.toBlob());

       return BinData::dataToString(encCon);

    }

    public static server EncryptedURLParameter decryptString(str _res)

    {

       CryptoAPI              cryptoAPI;

       container              decryptedContainer;

       ContainerClass         concls;

           cryptoAPI = new CryptoAPI(99999999999);

           decryptedContainer = BinData::stringToData(_res);

           concls=new ContainerClass([_res]);

                   decryptedContainer=cryptoAPI.encrypt(concls.toBlob());//encrypt

                   decryptedContainer = ContainerClass::blob2Container(cryptoAPI.decrypt(decryptedContainer));

                   info(con2Str(decryptedContainer));//info for test    

       return con2Str(decryptedContainer);    

    }

  • Sohaib Cheema Profile Picture
    49,443 User Group Leader on at

    Yes, it will return same data what you will pass,, using example I have given above.

    The reason is because, I am decrypting same string which I am encrypting.

  • SKO Profile Picture
    409 on at

    Sohaib,

    My requirement is that, I have an password field. and wanted to store the encrypted version in the database. so i am passing the password and the table stores it as encrypted. when i wanted to see the password i need to decrypt it so i want to use the decrypt method which will return the original password when i pass the decrypted  password to the method. can you please help me

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    If you are unable to accomplish this with pure AX code, it is very easy to use the .Net tools available natively in AX for example via the System.Security.Cryptography namespace:

    msdn.microsoft.com/.../system.security.cryptography(v=vs.110).aspx

    We have implemented something similar for our web users' password authentication with AES encryption and a salted password in AX, so it is definitely doable.

  • Muhammad Ozair Naeem Profile Picture
    272 on at

    Vilmos Kintera

    How do you suggest we encrypt our string using

    msdn.microsoft.com/.../system.security.cryptography(v=vs.110).aspx

    in AX?

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans