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()) |
std::string nawa::crypto::sha1 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get SHA-1 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation (40 chars). Otherwise, the hash will be binary (20 bytes). |
Definition at line 33 of file crypto.cpp.
std::string nawa::crypto::sha224 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get SHA-224 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (28 bytes). |
Definition at line 45 of file crypto.cpp.
std::string nawa::crypto::sha256 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get SHA-256 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (32 bytes). |
Definition at line 57 of file crypto.cpp.
std::string nawa::crypto::sha384 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get SHA-384 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (48 bytes). |
Definition at line 69 of file crypto.cpp.
std::string nawa::crypto::sha512 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get SHA-512 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation. Otherwise, the hash will be binary (64 bytes). |
Definition at line 81 of file crypto.cpp.
std::string nawa::crypto::md5 | ( | std::string const & | input, |
bool | hex = true |
||
) |
Get MD5 hash of a string.
input | String to hash. |
hex | If true (default), get hash in hexadecimal representation (32 chars). Otherwise, the hash will be binary (16 bytes). |
Definition at line 93 of file crypto.cpp.
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.
password | The password to hash. |
hashingEngine | The 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). |
Definition at line 105 of file crypto.cpp.
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).
password | Password (user input) to be verified. |
hash | Hash (e.g., from a database) to verify the user password against. |
hashTypeTable | Object 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. |
Definition at line 110 of file crypto.cpp.