Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string GetMD5Hash(const boost::filesystem::path& path)
- {
- byte result[MD5_DIGEST_LENGTH];
- boost::iostreams::mapped_file_source source(path);
- MD5((byte*)source.data(), source.size(), result); // OpenSSL
- std::ostringstream s;
- s << std::hex << std::setfill('0');
- for (byte c : result)
- s << std::setw(2) << (int)c;
- return s.str();
- }
- bool ChangeMD5Hash(const boost::filesystem::path& path)
- {
- boost::filesystem::path md5(path.string() + ".md5");
- if (boost::filesystem::exists(md5))
- boost::filesystem::remove(md5);
- if (boost::filesystem::exists(path))
- boost::filesystem::rename(path, md5);
- else
- return false;
- boost::random::mt19937 generator;
- boost::random::uniform_int_distribution<> random(1, 1024);
- boost::filesystem::ifstream istream(md5, std::ios::in | std::ios::binary);
- boost::filesystem::ofstream ostream(path, std::ios::out | std::ios::binary);
- if (!istream.is_open())
- return false;
- if (!ostream.is_open())
- return false;
- ostream << istream.rdbuf();
- ostream.seekp(istream.tellg());
- ostream.write("\0", random(generator));
- istream.close();
- ostream.close();
- return boost::filesystem::remove(md5);
- }
Advertisement
Add Comment
Please, Sign In to add comment