Tuesday, 26 April 2016

Encrypt and Decrypt Passwords using X++ in Ax 2012


  • Create a Class
  • In Properties Change the Property Runon : Server
In main method write the following code


public static void main(Args args)

{
    CryptoApi                           cryptoApi;
    Container                           cont,cont1;
    ContainerClass                      containerClass;
    ;

   /* Salt is like a password, While encrypting and descrypting the phrase, the CryptoAPI class has to instantiated with same salt(123456).
   The phrases/words are encrypted & decrypted based on the salt. */

    cryptoApi = new CryptoApi(123456);
    containerClass = new ContainerClass(["Rajendra"]);
    cont = CryptoApi.encrypt(containerClass.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));
}

No comments:

Post a Comment