Encryption is very useful for certain applications, but the NetSuite documentation can be confusing. This article will walk through using the crypto and encode module to easily encrypt and decrypt data.
function encrypt(stringToEncrypt) {
// Create the secret key
const skey = crypto.createSecretKey({
secret: "custsecret_encrypt_entity_secret",
encoding: encode.Encoding.UTF_8,
});
// Set up cipher
const cipher = crypto.createCipher({
algorithm: crypto.EncryptionAlg.AES,
key: skey,
});
//Add string as input
cipher.update({ input: id, });
//Encrpyt string
const cipherout = cipher.final({
outputEncoding: encode.Encoding.HEX,
});
//Pass "cipherout" data to decrypt string
decrypt(cipherout);
}
function decrypt(cipherout) {
// Create the secret key
var skey = crypto.createSecretKey({
secret: "custsecret_encrypt_entity_secret,
encoding: encode.Encoding.UTF_8,
});
// Set up cipher
var decipher = crypto.createDecipher({
algorithm: crypto.EncryptionAlg.AES,
key: skey,
iv: cipherout.iv,
});
//Add cipher text
decipher.update({
input: cipherout.ciphertext,
inputEncoding: encode.Encoding.HEX,
});
//Decrypt
var decipherout = decipher.final({
outputEncoding: encode.Encoding.UTF_8,
});
}
The two functions above show how you can encrypt a string, and then decrypt the output to retrieve the string again.
Related Article: Simple SuiteScript 1.0 Encryption | SS1
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 a 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!
If you have general questions about NetSuite or more specific questions about how our team can support your business, please don't hesitate to contact us. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small.
Tagged with Training