SeaSalt_AEAD_XChaCha


SeaSalt_AEAD_XChaCha

Encrypt and decrypt data using XChaCha20-Poly1305 AEAD encryption

Constructor

new SeaSalt_AEAD_XChaCha(stringopt, secretopt, boxopt, configopt)

Parameters
string:string (optional)

String to encrypt

secret:string (optional)

Password to use for encryption

box:string (optional)

Secret box to use with encryption

config:string (optional)

Configuration data

Properties
box:string (optional)

Secret box utilized in encryption

ciphertext:string (optional)

Ciphertext generated by the most recent encryption request

config:Object

AEAD Encryption Configuration

config.minimumEntropy:number = 1 (optional)

Minimum password entropy required

config.minimumKeyLength:number = 1 (optional)

Minimum password character length

config.minimumStrength:number = 0 (optional)

Minimum password strength

config.logger:function = config.log (optional)

Logging handler

Methods

decrypt(string, secret, boxopt):string

Decrypts a string optionally using a secret box.

Using a secret box allows you to let a user change passwords without needing to rewrite all encrypted data.

See SeaSalt_AEAD_SecretBox for more information.

Parameters
string:string

String to encrypt

secret:string

Password to use for encryption

box:SeaSalt_AEAD_SecretBox|string (optional)

Secret box ciphertext or instance

Returns
Type
:string

Returns the decrypted plaintext

Examples

Basic Usage

//  using the result from the example at keychain.encrypt
let aead = new SeaSalt_AEAD_XChaCha();
aead.decrypt('00002c4cdbf646c1bba6c3f543a104e78555069f3bf5ca09fc5b66c7201eca012d10f01cdf49c15654ec418f7cac0cd5a6b1d0', 'mybestsecretevar33');

//  returns a string like: Hello world

Secret Box Usage

//  this time we'll use a secret box
let secretbox = new SeaSalt_AEAD_SecretBox('mybestsecretevar33', aead.key());
aead.encrypt('Hello world', 'mybestsecretevar33', secretbox);

//  the user password opens a secret box which contains the actual encryption key

encrypt(string, secret, boxopt):string

Encrypts a string optionally using a secret box.

Each encryption has a unique nonce. The same string will never encrypt to the same ciphertext twice.

Using a secret box allows you to let a user change passwords without needing to rewrite all encrypted data.

See SeaSalt_AEAD_SecretBox for more information.

Parameters
string:string

String to encrypt

secret:string

Password to use for encryption

box:SeaSalt_AEAD_SecretBox|string (optional)

Secret box ciphertext or instance

Returns
Type
:string

Returns the encrypted ciphertext

Examples

Basic Usage

let aead = new SeaSalt_AEAD_XChaCha();
aead.encrypt('Hello world', 'mybestsecretevar33');

//  ciphertext in aead.ciphertext reads: 00002c4cdbf646c1bba6c3f543a104e78555069f3bf5ca09fc5b66c7201eca012d10f01cdf49c15654ec418f7cac0cd5a6b1d0

Secret Box Usage

//  this time we'll use a secret box
let secretbox = new SeaSalt_AEAD_SecretBox('mybestsecretevar33', aead.key());
aead.encrypt('Hello world', 'mybestsecretevar33', secretbox);

//  the user password opens a secret box which contains the actual encryption key

key():string

Generates a unique AEAD encryption key in hex format.

Returns
Type
:string

toJSON():string

Generate a JSON string containing encryption results

Returns
Type
:string