Netsuite | nlapiEncrypt – Is there a way to decrypt string value created by nlapiEncrypt?

As per Netsuite documentation, we can use nlapiEncrypt(s) and this will create and return string value using SHA-1 method.

HelpGuide > SuiteFlex (Customization, Scripting, and Web Services) > SuiteScript > SuiteScript API > SuiteScript Functions > Encryption APIs

By default, the nlapiEncrypt(s) will return a string sha-1 value, when you used the API by passing only the string to be encrypt, there is no way to decrypt the value.

However, if you want to use an encryption using the nlapiEncrypt API and decrypt it back you can use the nlapiDecrypt API.

Here is the step to implement encryption and decryption.

  1. Encryption – Use the nlapiEncrypt API, but make sure to pass three parameters:
  2. nlapiEncrypt(s, type, key)

    s = the string value that you want to encrypt.
    type = base64, aes, xor
    key = Unique string value that would serve as a ‘password’ in the decryption.

    Here is a sample implementation:

    nlapiEncrypt(“Eliseo”, “base64″, “Netsuite”);

    Result: “RWxpc2Vv”

  3. Decryption – use the nlapiDecrypt(s, type, key) API
  4. s = the string value returned by the nlapiEncrypt
    type = the encryption type used on the nlapiEncrypt (can only be: sha1, base64, aes and xor)
    key = Unique string value used on the nlapiEncrypt.

    Here is a sample implementation:

    nlapiDecrypt(“RWxpc2Vv”, “base64″, “Netsuite”)

    Result: “Eliseo”

Note: nlapiDecrypt is not documented in the official helpguide but it does exist.

No related posts.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>