CryptoSys PKI  23.0.0
Public Types | Static Public Member Functions | List of all members
dipki::Hmac Class Reference

Keyed-hash based message authentication code (HMAC) functions. More...

Public Types

enum class  Alg
 Hash algorithm used in HMAC More...
 

Static Public Member Functions

static bvec_t Bytes (const bvec_t &data, const bvec_t &key, Alg alg=Alg::Sha1)
 Compute HMAC over byte array. More...
 
static std::string HexFromBytes (const bvec_t &data, const bvec_t &key, Alg alg=Alg::Sha1)
 Compute HMAC in hex format over byte array. More...
 
static std::string HexFromHex (const std::string &dataHex, const std::string &keyHex, Alg alg=Alg::Sha1)
 Compute HMAC in hex format over hex-encoded input. More...
 
static std::string HexFromString (const std::string &s, const bvec_t &key, Alg alg=Alg::Sha1)
 Compute HMAC in hex format over string input. More...
 

Detailed Description

Keyed-hash based message authentication code (HMAC) functions.

Member Enumeration Documentation

◆ Alg

enum dipki::Hmac::Alg
strong

Hash algorithm used in HMAC

Enumerator
Sha1 

SHA-1 (default)

Md5 

MD5 (legacy)

Sha224 

SHA-224.

Sha256 

SHA-256.

Sha384 

SHA-384.

Sha512 

SHA-512.

Sha3_224 

SHA-3-224 (as per FIPS PUB 202)

Sha3_256 

SHA-3-256 (as per FIPS PUB 202)

Sha3_384 

SHA-3-384 (as per FIPS PUB 202)

Sha3_512 

SHA-3-512 (as per FIPS PUB 202)

Member Function Documentation

◆ Bytes()

static bvec_t dipki::Hmac::Bytes ( const bvec_t data,
const bvec_t key,
Alg  alg = Alg::Sha1 
)
static

Compute HMAC over byte array.

Parameters
dataMessage data in byte array.
keyKey in byte array
algHash algorithm to be used in HMAC (default = SHA-1).
Returns
HMAC digest in byte array.

◆ HexFromBytes()

static std::string dipki::Hmac::HexFromBytes ( const bvec_t data,
const bvec_t key,
Alg  alg = Alg::Sha1 
)
static

Compute HMAC in hex format over byte array.

Parameters
dataMessage data in byte array .
keyKey in byte array
algHash algorithm to be used in HMAC (default = SHA-1).
Returns
HMAC digest in hex-encoded format.
cout << dipki::Hmac::HexFromBytes(dipki::Cnv::FromHex("7768617420646f2079612077616e7420666f72206e6f7468696e673f"), dipki::Cnv::FromHex("4a656665"), dipki::Hmac::Alg::Sha256) << endl;
// 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
static bvec_t FromHex(const std::string &s)
Decodes a hexadecimal-encoded string as an array of bytes.
static std::string HexFromBytes(const bvec_t &data, const bvec_t &key, Alg alg=Alg::Sha1)
Compute HMAC in hex format over byte array.
@ Sha256
SHA-256.

◆ HexFromHex()

static std::string dipki::Hmac::HexFromHex ( const std::string &  dataHex,
const std::string &  keyHex,
Alg  alg = Alg::Sha1 
)
static

Compute HMAC in hex format over hex-encoded input.

Parameters
dataHexMessage data in hex-encoded format.
keyHexKey in hex-encoded format.
algHash algorithm to be used in HMAC (default = SHA-1).
Returns
HMAC digest in hex-encoded format.
cout << dipki::Hmac::HexFromHex("7768617420646f2079612077616e7420666f72206e6f7468696e673f", "4a656665", dipki::Hmac::Alg::Sha384) << endl;
// af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e8e2240ca5e69e2c78b3239ecfab21649
@ Sha384
SHA-384.
static std::string HexFromHex(const std::string &dataHex, const std::string &keyHex, Alg alg=Alg::Sha1)
Compute HMAC in hex format over hex-encoded input.

◆ HexFromString()

static std::string dipki::Hmac::HexFromString ( const std::string &  s,
const bvec_t key,
Alg  alg = Alg::Sha1 
)
static

Compute HMAC in hex format over string input.

Parameters
sMessage data string.
keyKey in byte array
algHash algorithm to be used in HMAC (default = SHA-1).
Returns
HMAC digest in hex-encoded format.
cout << dipki::Hmac::HexFromString("Hi There", dipki::Cnv::FromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")) << endl;
// b617318655057264e28bc0b6fb378c8ef146be00
static std::string HexFromString(const std::string &s, const bvec_t &key, Alg alg=Alg::Sha1)
Compute HMAC in hex format over string input.
Copyright © 2004-24 D.I. Management Services Pty Limited t/a CryptoSys ABN 78 083 210 584 Australia. All rights reserved. <www.di-mgt.com.au> <www.cryptosys.net>. Generated on Mon Sep 23 2024 15:37:33 by Doxygen 1.9.1.