Pbkdf2.Base.gen_salt

You're seeing just the function gen_salt, go back to Pbkdf2.Base module for more information.

Specs

gen_salt(keyword() | integer()) :: binary()

Generates a random salt.

This function takes one optional argument - a keyword list (see below for more details).

Options

The following options are available:

  • :salt_len - the length of the random salt
    • the default is 16 bytes
    • for more information, see the 'Salt length recommendations' section below
  • :format - the length of the random salt
    • the default is :modular (modular crypt format)
    • the other available options are :django and :hex

Examples

Here is an example of generating a salt with the default salt length and format:

Pbkdf2.Base.gen_salt()

To generate a different length salt:

Pbkdf2.Base.gen_salt(salt_len: 32)

And to generate a salt in Django output format:

Pbkdf2.Base.gen_salt(format: :django)

Salt length recommendations

In most cases, 16 bytes is a suitable length for the salt. It is not recommended to use a salt that is shorter than this (see below for details and references).

According to the Pbkdf2 standard, the salt should be at least 8 bytes long, but according to NIST recommendations, the minimum salt length should be 16 bytes.