Encryption is a powerful security measure that should be included in scripts, especially when dealing with sensitive data such as passwords. Unfortunately, the documentation for encryption in SuiteScript 1.0 (SS1) is limited. Therefore, I am providing the code below as a baseline for how to use it.
Note: The below method is known to function for strings. Be sure and stringify objects before attempting to encrypt them.
//this function is not required, but is an example of generating a random hex key.
function generateHexKey(length) {
var result = "";
var characters = "0123456789abcdef"; // Hexadecimal characters
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var dataToBeEncoded = "Encrypt Me";
var secretKey = generateHexKey(32);
var encodedData = nlapiEncrypt(data, "aes", secretKey);
//NOTE: "data" must be stringified
var decryptedData = nlapiDecrypt(encodedData, "aes", secretKey);
//decryptedData = "Encrypt Me"
There are a variety of ways to load in secret keys in SuiteScript 1.0. I recommend pursuing one of the following methods for loading your secret keys:
Be sure to choose the method that best suits your use case.
We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes there is a related feature to enable or field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!
Tagged with Training