crypto.createSecretKey(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Creates a new crypto.SecretKey object.

This method can take a GUID or the script ID of a secret stored at Setup > Company > API Secrets. Use Form.addCredentialField(options) to generate a GUID value. For more information about API Secrets, see Secrets Management.

Note:

When using the crypto.SecretKey object for an AES algorithm, the length of the text (secret key) that is used to generate the GUID must be 16, 24, or 32 characters.

Returns

A crypto.SecretKey object

Supported Script Types

Server scripts

For additional information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/crypto Module

Since

2015.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.guid

string

required if secret is not specified

A GUID used to generate a secret key.

The GUID can resolve to either data or metadata.

You can create a GUID using Form.addCredentialField(options).

This is only required if a secret is not provided. You cannot use the guid parameter in combination with the secret parameter.

2015.2

options.secret

string

required if options.guid is not specified

The script ID of the secret used for authentication. You can store secrets at Setup > Company > API Secrets. For more information, see Secrets Management.

This is only required if GUID is not provided. You cannot use the secret parameter in combination with the passwordGuid parameter.

2021.1

options.encoding

enum

optional

Specifies the encoding for the SecureKey.

Use the encode.Encoding enum to set the value.

The default value is encode.Encoding.HEX.

2015.2

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/crypto Module Script Samples.

          //Add additional code 
...
var secretKey = crypto.createSecretKey({
    encoding: encode.Encoding.UTF_8,
    guid: '284CFB2D225B1D76FB94D150207E49DF'
    });
...
//Add additional code 

        

Related Topics

N/crypto Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices