Sunday, May 13, 2012

Cryptography in AX using CryptoAPI class

    Hi Folks,

For some clients, you would require to encrypt some phrases or words like passwords. For this, we can use cryptography class(CryptoAPI) which would allow us to encrypt/decrypt the phrases. The following example explains about the CryptoAPI class.

    CryptoApi cryptoApi;
    Container cont,cont1;
    ContainerClass cc;
   /* Salt is like a password, While encrypting and descrypting the phrase, the CryptoAPI class has to instantiated with same salt(99999999999). The phrases/words are encrypted & decrypted based on the salt. */
    cryptoApi = new CryptoApi(99999999999);
    cc = new ContainerClass(["giridhar"]);
    cont = CryptoApi.encrypt(cc.toBlob()); // The encrypt method requires BLOB as a parameter
    cont1 = ContainerClass::blob2Container(CryptoApi.decrypt(cont));

Happy DAXing............


Rachit Garg said...

Nice piece of code, additionally CryptoAPI class cannot be initialized on client. So in order to execute the code we need to make sure it runs on server. we can test this by creating a new static method in a class and use server keyword so that it always runs on server.

Giridhar Raj said...

Yes Rachit, it needs to be initialized on the Server and not on client.....

ashu said...

getting error like
"CryptoAPI not available."

ashu said...

getting error lik
"CryptoAPI not available."

Sanjivkumar Kori said...

Hi Giridhar -

Need some info on the input parameter for CryptoAPI class, as of now it says only int64 - not sure how this works.


Sanjivkumar Kori said...

Hi Giridhar -

Please provide some information on the parameter used by CryptoAPI class, as of now it just says int64 type, not exactly getting how to map this to a salt key.


Sanjivkumar Kori said...

Hi Giridhar,

Please provide me some info on the CrytpoAPI parameter, as of now its just a int64 type, not able to exactly map it to a salt key.