Created
June 15, 2017 11:45
-
-
Save vossjannik/9bf288608d08fc60d54e2c59b5ba9f7f to your computer and use it in GitHub Desktop.
C++ Easy To Use SHA1 Function Based On Boost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string sha1(const std::string& str) | |
{ | |
using boost::uuids::detail::sha1; | |
sha1 sha; | |
sha.process_bytes(str.data(), str.size()); | |
unsigned hash[5] = {0}; | |
sha.get_digest(hash); | |
// back to string | |
char buf[41] = {0}; | |
for (int i = 0; i < 5; ++i) std::sprintf(buf + (i << 3), "%08x", hash[i]); | |
return buf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment