Cryptography in AX using CryptoAPI class
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…………
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.
Yes Rachit, it needs to be initialized on the Server and not on client…..
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.
Regards,
Koori
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.
Regards,
Kori.
Hi Giridhar –
Need some info on the input parameter for CryptoAPI class, as of now it says only int64 – not sure how this works.
Regards,
Kori
getting error lik
"CryptoAPI not available."
getting error like
"CryptoAPI not available."