SeaSalt_Common


SeaSalt_Common

SeaSalt Common Class

Constructor

new SeaSalt_Common(configopt)

Provides a single object with properties leading to each available class. For general use only when directly using the class isn't necessary.

Parameters
config:object (optional)

User configuration

Properties
config:object
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

config.secret:string

Default encryption password for encrypting and decrypting strings

config.pwhash:string = argon2 (optional)

Default password hashing class

config.pwsecurity:string = normal (optional)

Default password hashing strength

aead:object
aead.xchacha:SeaSalt_AEAD_XChaCha

An instance of SeaSalt_AEAD_XChaCha

hash:SeaSalt_Hashing

An instance of SeaSalt_Hashing

pwhash:object
pwhash.argon2:SeaSalt_PWHash_Argon2

An instance of SeaSalt_PWHash_Argon2

pwhash.scrypt:SeaSalt_PWHash_Argon2

An instance of SeaSalt_PWHash_SCrypt

secretbox:SeaSalt_AEAD_SecretBox

An instance of SeaSalt_AEAD_SecretBox

tools:SeaSalt_Tools

An instance of SeaSalt_Tools

Example

Basic Usage

//  most basic usage
let seasalt = new SeaSalt();

//  or include a config
let seasalt = new SeaSalt({
    minimumKeyLength: 12
});

Methods

aead_test():boolean

Test whether or not AEAD encryption is functioning.

Returns
Type
:boolean

Returns true or false.

decrypt(string, secretopt, boxopt):string

Decrypts supplied ciphertext with a known or provided password and optionally a secret box.

Parameters
string:string

String to encrypt

secret:string = config.password (optional)

Password to use for encryption

box:string (optional)

Secret box to utilize

Returns
Type
:string

Returns the decrypted plaintext.

encrypt(string, secretopt, boxopt):string

Encrypts supplied string with a known or provided password and optionally a secret box.

Parameters
string:string

String to encrypt

secret:string = config.password (optional)

Password to use for encryption

box:string (optional)

Secret box to utilize

Returns
Type
:string

Returns the encrypted ciphertext.

pwhash_create(password, securityopt, algorithmopt):string

Create a strong password hash using Argon2 or SCrypt.

Parameters
password:string

Password to hash

security:string = config.pwsecurity (optional)

Hashing strength

algorithm:string = config.pwhash (optional)

Hashing algorithm

Returns
Type
:string

Returns the password hash.

pwhash_verify(hash, password, algorithmopt):boolean

Checks a password against a password hash to check for validity using Argon2 or SCrypt.

Parameters
hash:string

Password hash to test against

password:string

Password to test

algorithm:string = config.pwhash (optional)

Hashing algorithm

Returns
Type
:boolean

Returns true or false.

test():boolean

Test whether or not Sodium is functioning.

Returns
Type
:boolean

Returns true or false.