Documentation
¶
Index ¶
Constants ¶
const ( DefaultIteration = 10_000 MinIteration = 1_000 MaxIteration = 1_000_000 DefaultKeyLength = 32 MinKeyLength = 8 MaxKeyLength = 1_024 )
Variables ¶
This section is empty.
Functions ¶
func GeneratePBKDF2 ¶
GeneratePBKDF2 generates a PBKDF2 key based on the given password, salt, iteration and key length.
The iteration and key length are parsed and validated before being used. The hash algorithm is case-insensitive and defaults to "sha512" if not supported. Supported hash algorithms are "md5", "sha1", "sha256", and "sha512".
The output string is in the format of "hashAlgo$salt$iteration$keyLength$hashedPassword".
func GetHashFunc ¶
GetHashFunc returns the given hash algorithm and a function to create a new instance of the hash algorithm.
The given hash algorithm is case-insensitive. If the given hash algorithm is not supported, it defaults to "sha512".
Supported hash algorithms are: - md5 - sha1 - sha256 - sha512
func ParseIteration ¶
ParseIteration returns the given iteration if it is within the valid range. Otherwise, it returns the default iteration.
func ParseKeyLength ¶
ParseKeyLength returns the given key length if it is within the valid range. Otherwise, it returns the default key length.
func ValidatePBKDF2 ¶
ValidatePBKDF2 validates the given hash string against the given password.
The given hash string is expected to be in the format of "pbkdf2_<hashAlgo>$<salt>$<iteration>$<keyLength>$<hashedPassword>". The given password is hashed using the given hash string's algorithm, salt, iteration, and key length. If the generated hash string matches the given hash string, the function returns true. Otherwise, it returns false.
Types ¶
This section is empty.