Contact Us

NetSuite Encryption

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.

Clarifications Around NetSuite Data Encryption

  1. Make sure your encryption algorithm used is the same when setting up the cipher.
  2. The secret key:
  • Make sure you encode the secret key using the same encoding method when encrypting and decrypting.
  • The secret key “string” is the id of a secret set up under Setup > Company > API Secrets. Make sure it is allowed on scripts.

Got stuck on a step in this article?

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!

Oracle NetSuite Alliance Partner & Commerce Partner

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.

Horizontal Anchor Group logo orange anchor icon navy Anchor Group text

Tagged with Training