/cpp-hash-utils

C++ utilities to generate hash

Primary LanguageC++

Build Status Build status codecov Codacy Badge

C++ Utilities for Hashes

This repository offers a set of utilities to generate hashes using the most popular algorithms. They are implemented based on OpenSSL library, but offering a much simpler interface.

Supported hash functions

Setup

Download using Conan

This library is designed to be installed by making use of Conan package manager. So, you just need to add the following requirement into your Conan recipe:

def requirements(self):
   self.requires("HashUtils/1.0.0@systelab/stable")

Version number of this code snipped is set just as an example. Replace it for the desired package version to retrieve.

As this package is not available on the conan-center, you will also need to configure a remote repository before installing dependencies:

conan remote add systelab-public https://systelab.jfrog.io/artifactory/api/conan/cpp-conan-production-local

See Conan documentation for further details on how to integrate this package with your build system.

Build from sources

See BUILD.md document for details.

Usage

Create an instance of the systelab::hash::HashUtilsFactory class to build the services that implement the supported the hash algorithms:

#include "HashUtils/HashUtilsFactory"
#include "HashUtils/IHashService.h"

systelab::hash::HashUtilsFactory hashUtilsFactory;

SHA-256

The SHA-256 hash of an string value can be computed as follows:

std::string hash = hashUtilsFactory.buildSHA256HashService()->computeHash("Value to be hashed");

MD5

The MD5 hash of an string value can be computed in analogous manner:

std::string hash = hashUtilsFactory.buildMD5HashService()->computeHash("Value to be hashed");