CppSecurity  1.1.1.0
C++ Security Library
Public Member Functions | List of all members
CppSecurity::PBKDF2PasswordHashing Class Reference

'PBKDF2' password hashing algorithm More...

#include <password_hashing_pbkdf2.h>

Inheritance diagram for CppSecurity::PBKDF2PasswordHashing:
CppSecurity::PasswordHashing

Public Member Functions

 PBKDF2PasswordHashing (size_t hash_length=32, size_t salt_length=32, PBKDF2 algorithm=PBKDF2::HMAC_SHA512, size_t iterations=1000)
 Initialize 'PBKDF2' password hashing with required parameters. More...
 
 PBKDF2PasswordHashing (const PBKDF2PasswordHashing &)=default
 
 PBKDF2PasswordHashing (PBKDF2PasswordHashing &&)=default
 
 ~PBKDF2PasswordHashing ()=default
 
PBKDF2PasswordHashingoperator= (const PBKDF2PasswordHashing &)=default
 
PBKDF2PasswordHashingoperator= (PBKDF2PasswordHashing &&)=default
 
PBKDF2 algorithm () const noexcept
 Get the 'PBKDF2' algorithm. More...
 
size_t iterations () const noexcept
 Get the count of 'PBKDF2' iterations. More...
 
const std::string & name () const override
 Get the password hashing algorithm name. More...
 
std::string GenerateHash (std::string_view password, std::string_view salt) const override
 Generate the strong password hash for the given user password and unique salt. More...
 
bool Validate (std::string_view password, std::string_view hash, std::string_view salt) const override
 Validate the user password over the given strong password hash and unique salt. More...
 
- Public Member Functions inherited from CppSecurity::PasswordHashing
 PasswordHashing (size_t hash_length=32, size_t salt_length=32)
 Initialize password hashing with required parameters. More...
 
 PasswordHashing (const PasswordHashing &)=default
 
 PasswordHashing (PasswordHashing &&)=default
 
virtual ~PasswordHashing ()=default
 
PasswordHashingoperator= (const PasswordHashing &)=default
 
PasswordHashingoperator= (PasswordHashing &&)=default
 
size_t hash_length () const noexcept
 Get the strong password hash length. More...
 
size_t salt_length () const noexcept
 Get the unique password salt length. More...
 
virtual std::string GenerateSalt () const
 Generate the unique password salt. More...
 
virtual std::pair< std::string, std::string > GenerateHashAndSalt (std::string_view password) const
 Generate the strong password hash and unique salt for the given user password. More...
 
virtual std::string GenerateDigest (std::string_view password) const
 Generate the secure digest string for the given user password. More...
 
virtual std::string GenerateEncodedDigest (std::string_view password) const
 Generate the secure Base64 digest string for the given user password. More...
 
virtual bool ValidateDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure digest string. More...
 
virtual bool ValidateEncodedDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure Base64 digest string. More...
 

Detailed Description

'PBKDF2' password hashing algorithm

'PBKDF2' (Password-Based Key Derivation Function 2) are key derivation functions with a sliding computational cost, used to reduce vulnerabilities to brute force attacks.

'PBKDF2' is part of RSA Laboratories' Public-Key Cryptography Standards (PKCS) series, specifically PKCS #5 v2.0, also published as Internet Engineering Task Force's RFC 2898. It supersedes PBKDF1, which could only produce derived keys up to 160 bits long. RFC 8018, published in 2017, recommends PBKDF2 for password hashing.

https://en.wikipedia.org/wiki/PBKDF2

Thread-safe.

Examples
password_hashing_pbkdf2.cpp.

Definition at line 47 of file password_hashing_pbkdf2.h.

Constructor & Destructor Documentation

◆ PBKDF2PasswordHashing() [1/3]

CppSecurity::PBKDF2PasswordHashing::PBKDF2PasswordHashing ( size_t  hash_length = 32,
size_t  salt_length = 32,
PBKDF2  algorithm = PBKDF2::HMAC_SHA512,
size_t  iterations = 1000 
)

Initialize 'PBKDF2' password hashing with required parameters.

Parameters
hash_length- Strong password hash length (default is 32)
salt_length- Unique password salt length (default is 32)
algorithm- 'PBKDF2' algorithm (default is PBKDF2::HMAC_SHA512)
iterations- Count of 'PBKDF2' iterations (default is 1000)

Definition at line 17 of file password_hashing_pbkdf2.cpp.

◆ PBKDF2PasswordHashing() [2/3]

CppSecurity::PBKDF2PasswordHashing::PBKDF2PasswordHashing ( const PBKDF2PasswordHashing )
default

◆ PBKDF2PasswordHashing() [3/3]

CppSecurity::PBKDF2PasswordHashing::PBKDF2PasswordHashing ( PBKDF2PasswordHashing &&  )
default

◆ ~PBKDF2PasswordHashing()

CppSecurity::PBKDF2PasswordHashing::~PBKDF2PasswordHashing ( )
default

Member Function Documentation

◆ algorithm()

PBKDF2 CppSecurity::PBKDF2PasswordHashing::algorithm ( ) const
inlinenoexcept

Get the 'PBKDF2' algorithm.

Definition at line 66 of file password_hashing_pbkdf2.h.

◆ GenerateHash()

std::string CppSecurity::PBKDF2PasswordHashing::GenerateHash ( std::string_view  password,
std::string_view  salt 
) const
overridevirtual

Generate the strong password hash for the given user password and unique salt.

Parameters
password- User password
salt- Unique password salt
Returns
Strong password hash

Implements CppSecurity::PasswordHashing.

Definition at line 24 of file password_hashing_pbkdf2.cpp.

◆ iterations()

size_t CppSecurity::PBKDF2PasswordHashing::iterations ( ) const
inlinenoexcept

Get the count of 'PBKDF2' iterations.

Definition at line 68 of file password_hashing_pbkdf2.h.

◆ name()

const std::string& CppSecurity::PBKDF2PasswordHashing::name ( ) const
inlineoverridevirtual

Get the password hashing algorithm name.

Implements CppSecurity::PasswordHashing.

Definition at line 71 of file password_hashing_pbkdf2.h.

◆ operator=() [1/2]

PBKDF2PasswordHashing& CppSecurity::PBKDF2PasswordHashing::operator= ( const PBKDF2PasswordHashing )
default

◆ operator=() [2/2]

PBKDF2PasswordHashing& CppSecurity::PBKDF2PasswordHashing::operator= ( PBKDF2PasswordHashing &&  )
default

◆ Validate()

bool CppSecurity::PBKDF2PasswordHashing::Validate ( std::string_view  password,
std::string_view  hash,
std::string_view  salt 
) const
overridevirtual

Validate the user password over the given strong password hash and unique salt.

Parameters
password- User password
hash- Strong password hash
salt- Unique password salt
Returns
'true' if the given user password is valid, 'false' if the given user password is invalid

Implements CppSecurity::PasswordHashing.

Definition at line 46 of file password_hashing_pbkdf2.cpp.


The documentation for this class was generated from the following files: