Random

Random

Source:

Methods

(static) initNistKat(entropy, personalizationStringopt)

Source:

Generates cryptographically-secure random bytes.

Parameters:
Name Type Attributes Description
entropy Buffer

The entropy input seed. Must be exactly 48 bytes long.

personalizationString Buffer <optional>

A personalization string. Must be at least 48 bytes long if provided.

Throws:

Will throw an error if any argument is invalid.

Type
TypeError

(static) randomBytes(size) → {Buffer}

Source:

Generates cryptographically-secure random bytes.

Parameters:
Name Type Description
size number

The size of the returned Buffer.

Throws:
  • Will throw an error if any argument is invalid.

    Type
    TypeError
  • Will throw an error if memory cannot be allocated.

    Type
    Error
Returns:

bytes - A Buffer with size random bytes.

Type
Buffer

(static) switchAlgorithm(algorithm)

Source:

Switches the PRNG algorithm used by the library.

Parameters:
Name Type Description
algorithm Random.Algorithm

The PRNG algorithm to use.

Throws:

Will throw an error if any argument is invalid.

Type
TypeError

Type Definitions

Algorithm

Source:

The different PRNG algorithms that can be used. It can be one of the following:

  • system: System PRNG. Reads directly from /dev/urandom.
  • NIST-KAT: NIST deterministic RNG for KATs.
  • OpenSSL: OpenSSL's PRNG. Defaults to system.
Type:
  • string