Hash
Overview
Provides the hashing functionality required for RSA::sign and RSA::verify, but it can also be used as a standalone hasher.
Supported algorithms are directly provided by OpenSSL.
Hash
Provides hashing functionality required for sign and verify functions,
but can be also used independently.
tancrypt::hash(dutils::dbuffer& data,hashAlg alg)
- Parameters:
dutils::dbuffer& data- Data buffer to hashtancrypt::hashAlg alg- Algorithm to use for the digest.
- Returns:
dutils::dbuffer data- Hashed data buffer
Example
#include <iostream>
#include "tancrypt/hash.hpp"
int main()
{
// Data setup
dutils::dbuffer payload("Hewwo, I am secret ^.^");
// Data gets hashed here
dutils::dbuffer hashed_payload = tancrypt::hash(payload,tancrypt::hashAlg::SHA256);
// You can check the results via helper function dutils::hexStr
std::cout << "Original:" << payload.toStr() << std::endl;
std::cout << "Original(hex):" << dutils::hexStr(payload) << std::endl;
std::cout << "Hashed:" << hashed_payload.toStr() << std::endl;
std::cout << "Hashed(hex):" << dutils::hexStr(hashed_payload) << std::endl;
return 0;
}
hashAlg
Enum class used as hash type.
enum class tancrypt::hashAlg : int
Available algorithms:
| Enum Constant | Hashing algorithm | Digest Size | |
|---|---|---|---|
hashAlg::MDC2 |
MDC-2 | 128-bit | |
hashAlg::MD4 |
MD4 | 128-bit | |
hashAlg::MD5 |
MD5 | 128-bit | |
hashAlg::SHA1 |
SHA-1 | 160-bit | |
hashAlg::RSA_SHA1 |
RSA-SHA1 | 160-bit | |
hashAlg::SHA224 |
SHA-224 | 224-bit | |
hashAlg::SHA256 |
SHA-256 | 256-bit | |
hashAlg::SHA384 |
SHA-384 | 384-bit | |
hashAlg::SHA512 |
SHA-512 | 512-bit | |
hashAlg::SHA512_224 |
SHA-512-224 | 1024-bit | |
hashAlg::SHA512_256 |
SHA-512-256 | 1024-bit | |
hashAlg::SM3 |
ShangMi 3 | 512-bit | |
hashAlg::BLAKE2B512 |
BLAKE2B-512 | 1024-bit | |
hashAlg::BLAKE2S256 |
BLAKE2S-256 | 1024-bit |