/cpp-cryptlite

C++ library that supports base64-encoding, sha1/sha256 hashing, and hmac calculation

Primary LanguageC++MIT LicenseMIT

=======================================================================
 DESCRIPTION
=======================================================================

=======================================================================
 DEPENDENCIES
=======================================================================
<boost/utility.hpp>


=======================================================================
 SYNOPSIS
=======================================================================
#include <cryptlite/base64.h>
#include <cryptlite/sha1.h>
#include <cryptlite/sha256.h>
#include <cryptlite/hmac.h>
#include <boost/cstdint.hpp>

using namespace cryptlite;

// base64 encoding
std::string b64 = base64::encode_from_string("foobarbuz");

std::vector<boost::uint8_t> decoded_v;
base64::decode(b64, decoded_v);

std::string decoded_str;
base64::decode(b64, decoded_str);


boost::shared_array<boost::uint8_t> arr;
std::size_t len;
boost::tie(arr, len) = base64::decode_to_array(b64);

// sha1 hash
boost::uint8_t sha1digest[sha1::HASH_SIZE];
sha1::hash("foobar", sha1digest);

// hex-formatted sha1 hash
std::string sha1hex = sha1::hash_hex("foobar");

// base64-formatted sha1 hash
std::string sha1base64 = sha1::hash_base64("foobar");

// sha256 hash
boost::uint8_t sha256digest[sha256::HASH_SIZE];
sha256::hash("foobar", sha256digest);

// hex-formatted sha256 hash
std::string sha256hex = sha256::hash_hex("foobar");

// base64-formatted sha256 hash
std::string sha256base64 = sha256::hash_base64("foobar");

// calculate hmac-sha1
boost::uint8_t hmacsha1digest[sha1::HASH_SIZE];
hmac<sha1>::calc("basestring", "key", hmacsha1digest);

// calculate hex-formatted hmac-sha1
std::string hmacsha1hex = hmac<sha1>::calc_hex("basestring", "key");

// calculate hmac-sha256
boost::uint8_t hmacsha256digest[sha256::HASH_SIZE];
hmac<sha256>::calc("basestring", "key", hmacsha256digest);

// calculate hex-formatted hmac-sha256
std::string hmacsha256hex = hmac<sha256>::calc_hex("basestring", "key");

=======================================================================
 INSTALL
=======================================================================
This is header-only library.
So, copying include/cryptlite/*.h into your project directory is the easiest way.

or

1. cd build
2. cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release

parameters
    - BUILD_SHARED_LIBS (ON|OFF)
    - CMAKE_BUILD_TYPE (Debug|Release)
    - CMAKE_INSTALL_PREFIX (/usr/local)

3. make
4. make test
5. make install