lyokato / cpp-cryptlite Goto Github PK
View Code? Open in Web Editor NEWC++ library that supports base64-encoding, sha1/sha256 hashing, and hmac calculation
License: MIT License
C++ library that supports base64-encoding, sha1/sha256 hashing, and hmac calculation
License: MIT License
======================================================================= 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
Are you accepting pull requests?
C++14 is now 10 years old. #include <cstdint>
, std::shared_ptr
, making classes non-copyable are now first class language and library features. Do you have any objections to an update rather than a fork?
For the manual of the Readme file, I've just created a build directory, run cmake as it follows on the second point of manual, and tried to call "make".
But I've got a problem:
Wed 21 Apr - 12:31 ~/projects/github/cpp-cryptlite origin ☊ master ✔
user@localhost mkdir build
Wed 21 Apr - 12:31 ~/projects/github/cpp-cryptlite origin ☊ master ✔ user@localhost cd build
Wed 21 Apr - 12:31 ~/projects/github/cpp-cryptlite/build origin ☊ master ✔
user@localhost cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1 -- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features -- Detecting C compile features - done
-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/include (found version "1.67.0") -- Configuring done
-- Generating done -- Build files have been written to: /home/user/projects/github/cpp-cryptlite/build
Wed 21 Apr - 12:31 ~/projects/github/cpp-cryptlite/build origin ☊ master ✔
user@localhost make
Scanning dependencies of target gtest-main
[ 8%] Building CXX object gtest/CMakeFiles/gtest-main.dir/src/gtest_main.cc.o
[ 16%] Linking CXX static library libgtest-main.a
[ 16%] Built target gtest-main
Scanning dependencies of target gtest
[ 25%] Building CXX object gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 33%] Linking CXX static library libgtest.a
[ 33%] Built target gtest
Scanning dependencies of target sha256Test
[ 41%] Building CXX object tests/CMakeFiles/sha256Test.dir/sha256Test.cpp.o
[ 50%] Linking CXX executable sha256Test
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::UnitTestImpl::~UnitTestImpl()':
gtest-all.cc:(.text+0x3734): undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text+0x374f): undefined reference to `pthread_key_delete'
/usr/bin/ld: gtest-all.cc:(.text+0x39ad): undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text+0x39c5): undefined reference to `pthread_key_delete'
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::UnitTestImpl::UnitTestImpl(testing::UnitTest*)':
gtest-all.cc:(.text+0xfc47): undefined reference to `pthread_key_create'
/usr/bin/ld: gtest-all.cc:(.text+0xfde7): undefined reference to `pthread_key_create'
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED
5Ev]+0xc): undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporte
rInterfaceEED5Ev]+0x21): undefined reference to `pthread_key_delete'
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::Tr
aceInfo> > >::~ThreadLocal()':
gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0xe):
undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_E
EED5Ev]+0x25): undefined reference to `pthread_key_delete'
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::Tr
aceInfo> > >::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESa
IS3_EEE16GetOrCreateValueEv]+0x14): undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_
9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x163): undefined reference to `pthread_setspecific'
/usr/bin/ld: ../gtest/libgtest.a(gtest-all.cc.o): in function `testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::GetOrCreateValue() const':
gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultRe
porterInterfaceEE16GetOrCreateValueEv]+0xc): undefined reference to `pthread_getspecific'
/usr/bin/ld: gtest-all.cc:(.text._ZNK7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalIPNS_31Tes
tPartResultReporterInterfaceEE16GetOrCreateValueEv]+0x56): undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/CMakeFiles/sha256Test.dir/build.make:105: tests/sha256Test] Error 1
make[1]: *** [CMakeFiles/Makefile2:239: tests/CMakeFiles/sha256Test.dir/all] Error 2
make: *** [Makefile:160: all] Error 2
{code}
What should I do to solve it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.