Skip to content

Variable: random ​

ts
random: object;

Random number generation functions for generating salts and random values.

Type declaration ​

Generate Salt ​

generateSalt() ​

ts
generateSalt(length): Promise<string>;

Generates a cryptographically secure random salt value as a hexadecimal string.

Parameters ​
length ​

number = 16

The length of the salt in bytes. Defaults to 16.

Returns ​

Promise<string>

A Promise that resolves to a hexadecimal string representing the generated salt.

Throws ​

Will throw an error if the length is less than or equal to 0.

Example ​
js
const salt = await cryptor.random.generateSalt();
console.log(salt); // Outputs a random hexadecimal string of length 16.