Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vossjannik/9bf288608d08fc60d54e2c59b5ba9f7f to your computer and use it in GitHub Desktop.
Save vossjannik/9bf288608d08fc60d54e2c59b5ba9f7f to your computer and use it in GitHub Desktop.
C++ Easy To Use SHA1 Function Based On Boost
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