SeaSalt_AEAD_SecretBox


SeaSalt_AEAD_SecretBox

Create a secret box to store information with a changeable password.

Constructor

new SeaSalt_AEAD_SecretBox(userPasswordopt, secretItemopt, configopt)

Parameters
userPassword:string (optional)

Password for the secret box

secretItem:string (optional)

Item to store inside the secret box

config:object (optional)

User-provided Configuration data

At a basic level this is a glorified encrypted string.

A typical usage for a secret box is to store an AEAD encryption key. The password on the secret box can change without requiring any encrypted data be re-encrypted.

You can also store a JSON object with any data you want along with an encryption key.

Properties
box:string

Secret box ciphertext once generated

config:Object

Configuration data

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

Logging handler

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

Methods

check(box, userPassword, secretItemopt):boolean

Check if a secret box is valid and/or readable.

Parameters
box:string

Secret box to repackage

userPassword:string

Password of the existing secret box

secretItem:string (optional)

Item to check for inside the secret box

Returns
Type
:boolean

Returns true or false

Example
//  using the result from the example in keychain.create
let secretbox = new SeaSalt_AEAD_SecretBox();
secretbox.check('077eb44fc4d04ad6093f6ab5c1938c151c07fd9fb360234670a7e0da4530aa3f...', 'mygreatpassword1');

//  result would return true or false

create(userPassword, secretItem):string

Create a secret box with the provided item.

Parameters
userPassword:string

Password for the secret box

secretItem:string

Item to place inside the box

Returns
Type
:string

Returns the secret box ciphertext.

Examples

Basic Usage

let aead = new SeaSalt_AEAD_XChaCha();
let secretbox = new SeaSalt_AEAD_SecretBox();
secretbox.create('mygreatpassword1', aead.key());

//  returns a string like: 077eb44fc4d04ad6093f6ab5c1938c151c07fd9fb360234670a7e0da4530aa3f...

Using a Secret Box with AEAD Encryption

let aead = new SeaSalt_AEAD_XChaCha();
let secretbox = new SeaSalt_AEAD_SecretBox();
secretbox.create('mygreatpassword1', aead.key());
let ciphertext = aead.encrypt('My great string', 'mygreatpassword1', secretbox);

//  returns the encrypted ciphertext using the encryption key stored in the secret box

repackage(box, userPassword, newPassword):string

Repackages a secret box and optionally changes its password.

This will re-encrypt the contents of a secret box resulting in new secret box ciphertext.

Parameters
box:string

Secret box to repackage

userPassword:string

Password of the existing secret box

newPassword:string

New password to set on the secret box

Returns
Type
:string

Returns the secret box ciphertext.

Example
let secretbox = new SeaSalt_AEAD_SecretBox('mygreatpassword1', aead.key());

//  repackage with same password
secretbox.repackage('mygreatpassword1');

//  repackage with new password
secretbox.repackage('mygreatpassword1', 'evenbettarp4ssword');

//  repackage with a supplied box
secretbox.repackage('077eb44fc4d04ad6093f6ab5c1938c151c07fd9fb360234670a7e0da4530aa3f...', 'mygreatpassword1');

toString():string

Returns the secret box ciphertext.

Returns
Type
:string