Skip to content

Instantly share code, notes, and snippets.

@syohex
Created September 12, 2020 16:25
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 syohex/f3cc0cdb651b821e5c0b0aaf01c11bff to your computer and use it in GitHub Desktop.
Save syohex/f3cc0cdb651b821e5c0b0aaf01c11bff to your computer and use it in GitHub Desktop.
g++ -std=c++17 md5.cpp -lcryptopp
#include <crypto++/files.h>
#include <crypto++/hex.h>
#include <crypto++/md5.h>
#include <filesystem>
#include <string>
namespace {
std::string md5(const std::filesystem::path &file) {
std::string ret;
CryptoPP::MD5 hash;
CryptoPP::FileSource f(
file.c_str(), true,
new CryptoPP::HashFilter(
hash, new CryptoPP::HexEncoder(new CryptoPP::StringSink(ret))));
return ret;
}
} // namespace
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cerr << "Usage: md5 file" << std::endl;
return 1;
}
std::cout << argv[1] << ": " << md5(std::filesystem::path{argv[1]})
<< std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment