NAWA 0.9
Web Application Framework for C++
nawa::crypto Namespace Reference

Functions

std::string sha1 (std::string const &input, bool hex=true)
 
std::string sha224 (std::string const &input, bool hex=true)
 
std::string sha256 (std::string const &input, bool hex=true)
 
std::string sha384 (std::string const &input, bool hex=true)
 
std::string sha512 (std::string const &input, bool hex=true)
 
std::string md5 (std::string const &input, bool hex=true)
 
std::string passwordHash (std::string const &password, hashing::HashingEngine const &hashingEngine=hashing::BcryptHashingEngine())
 
bool passwordVerify (std::string const &password, std::string const &hash, hashing::HashTypeTable const &hashTypeTable=hashing::DefaultHashTypeTable())
 

Function Documentation

◆ sha1()

std::string nawa::crypto::sha1 ( std::string const &  input,
bool  hex = true 
)

Get SHA-1 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation (40 chars). Otherwise, the hash will be binary (20 bytes).
Returns
SHA-1 hash of input.

Definition at line 33 of file crypto.cpp.

◆ sha224()

std::string nawa::crypto::sha224 ( std::string const &  input,
bool  hex = true 
)

Get SHA-224 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (28 bytes).
Returns
Hash of input.

Definition at line 45 of file crypto.cpp.

◆ sha256()

std::string nawa::crypto::sha256 ( std::string const &  input,
bool  hex = true 
)

Get SHA-256 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (32 bytes).
Returns
Hash of input.

Definition at line 57 of file crypto.cpp.

◆ sha384()

std::string nawa::crypto::sha384 ( std::string const &  input,
bool  hex = true 
)

Get SHA-384 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (48 bytes).
Returns
Hash of input.

Definition at line 69 of file crypto.cpp.

◆ sha512()

std::string nawa::crypto::sha512 ( std::string const &  input,
bool  hex = true 
)

Get SHA-512 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (64 bytes).
Returns
Hash of input.

Definition at line 81 of file crypto.cpp.

◆ md5()

std::string nawa::crypto::md5 ( std::string const &  input,
bool  hex = true 
)

Get MD5 hash of a string.

Parameters
inputString to hash.
hexIf true (default), get hash in hexadecimal representation (32 chars). Otherwise, the hash will be binary (16 bytes).
Returns
Hash of input.

Definition at line 93 of file crypto.cpp.

◆ passwordHash()

std::string nawa::crypto::passwordHash ( std::string const &  password,
hashing::HashingEngine const &  hashingEngine = hashing::BcryptHashingEngine() 
)

Create a (hopefully) secure password hash using a hash algorithm (bcrypt by default).
This function returns one-way hashes with pseudo-random salts. Use passwordVerify to validate a password.
May throw a nawa::Exception on failure, the error codes are defined by the underlying hashing engine, but should not be lower than 10. Argon2 hashing might be added later, probably in a separate function.

Parameters
passwordThe password to hash.
hashingEngineThe hashing engine (containing the hashing algorithm) to use. This will (currently) default to bcrypt. You can pass an object to a hashing engine if you want to use another algorithm or in case you wish to customize hashing properties (such as using your own salt or changing the work factor).
Returns
Hash of the password (in case of bcrypt: 60 characters).

Definition at line 105 of file crypto.cpp.

◆ passwordVerify()

bool nawa::crypto::passwordVerify ( std::string const &  password,
std::string const &  hash,
hashing::HashTypeTable const &  hashTypeTable = hashing::DefaultHashTypeTable() 
)

Validate a password with a matching hashing engine (determined by a HashTypeTable). The underlying function of the hashing engine should be designed in a way that prevents timing attacks (given that the compiler did no bad optimizations).
May throw a nawa::Exception on failure. Error codes: 1 (empty input hash), 2 (no hashing engine able to verify the given hash could be determined by the HashTypeTable).

Parameters
passwordPassword (user input) to be verified.
hashHash (e.g., from a database) to verify the user password against.
hashTypeTableObject providing a function that is able to determine a hashing engine that can verify the given hash. The default HashTypeTable shipped with NAWA recognizes all hashing engines that also ship with NAWA.
Returns
True if the password matches, false otherwise.

Definition at line 110 of file crypto.cpp.