Created
September 12, 2020 16:25
-
-
Save syohex/f3cc0cdb651b821e5c0b0aaf01c11bff to your computer and use it in GitHub Desktop.
g++ -std=c++17 md5.cpp -lcryptopp
This file contains hidden or 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
#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