Skip to content

Hashing (SHA / bcrypt)

SHA-256 Hashing

The sha256::compute function returns a hex-encoded SHA-256 hash of the input.

cpp
#include <framework/support/cipher.hpp>

using namespace framework;
using namespace framework::support::cipher;

// Returns hex-encoded hash
auto hash = sha256::compute("data to hash");

// With output buffer
std::string out;
sha256::compute("data to hash", out);

Use cases: Checksums, content integrity verification, data fingerprinting.


bcrypt Password Hashing

bcrypt is a password hashing function designed to be computationally expensive, making brute-force attacks harder.

password::hash(password, workload) — Hash a password

cpp
// Hash with default workload (12)
auto hash = password::hash("user_password");

// Hash with custom workload (4-31, higher = slower)
auto hash = password::hash("user_password", 10);
ParamDefaultDescription
passwordThe plaintext password.
workload12Cost factor (2^workload iterations). Higher values are slower but more secure.

password::verify(password, hash) — Verify a password

cpp
bool matches = password::verify("user_password", stored_hash);
if (matches) {
    fmt::println("Password is correct");
}