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));
    info(Strfmt("Encrypted:%1",BinData::dataToString(cont)));
    info(con2str(cont1));

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

Saturday, May 12, 2012