forked from lyokato/cpp-cryptlite
C++ library that supports base64-encoding, sha1/sha256 hashing, and hmac calculation
License
wadarochi/cpp-cryptlite
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
======================================================================= DESCRIPTION ======================================================================= ======================================================================= DEPENDENCIES ======================================================================= C++17 ======================================================================= SYNOPSIS ======================================================================= #include <cryptlite/base64.h> #include <cryptlite/sha1.h> #include <cryptlite/sha256.h> #include <cryptlite/hmac.h> #include <cstdint> #include <memory> using namespace cryptlite; // base64 encoding std::string b64 = base64::encode_from_string("foobarbuz"); std::vector<uint8_t> decoded_v; base64::decode(b64, decoded_v); std::string decoded_str; base64::decode(b64, decoded_str); std::unique_ptr<uint8_t[]> arr; std::size_t len; auto result = base64::decode_to_array(b64); arr = std::move(std::get<0>(result)); len = std::get<1>(result); // sha1 hash 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 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 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 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
About
C++ library that supports base64-encoding, sha1/sha256 hashing, and hmac calculation
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- C++ 99.0%
- Other 1.0%