Utility Methods API for JavaScript SDK
The methods on this page are utility methods that don't fit into other categories.
Encrypt
This function allows to encrypt
the data.
Deprecated parameter
The cipherKey
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To encrypt
the data, you can use the following method(s) in JavaScript SDK.
encrypt(
data: string,
customCipherKey?: string
)
Parameter | Description |
---|---|
data *Type: string or bytes | The data to encrypt . |
customCipherKey Type: string | If provided, the legacy encryption with 128-bit cipher key entropy is used. |
Basic Usage
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
Encrypt part of message
Returns
It returns the encrypted data
as string.
Encrypt File
This function allow to encrypt
the file content/data.
Deprecated
The key
parameter in this method is deprecated. We recommend that you configure a separate instance of the crypto module and use it for partial encryption.
If you pass cipherKey
as an argument, it overrides the crypto module configuration and the legacy encryption with 128-bit cipher key entropy is used.
Method(s)
To encrypt
the file, you can use the following method(s) in JavaScript SDK.
pubnub.encryptFile(
key: string,
file: PubNubFile
): Promise<PubNubFile>;
Parameter | Description |
---|---|
key Type: string | Cipher key used for encryption. |
file *Type: PubNubFile | File to encrypt. |