C++ 使用Boost库计算MD5值
·
代码如下:
#include <boost/algorithm/hex.hpp>
#include <boost/uuid/detail/md5.hpp>
bool GetMd5(std::string &str_md5, const char * const buffer, size_t buffer_size)
{
if (buffer == nullptr)
{
return false;
}
boost::uuids::detail::md5 boost_md5;
boost_md5.process_bytes(buffer, buffer_size);
boost::uuids::detail::md5::digest_type digest;
boost_md5.get_digest(digest);
const auto char_digest = reinterpret_cast<const char*>(&digest);
str_md5.clear();
boost::algorithm::hex(char_digest,char_digest+sizeof(boost::uuids::detail::md5::digest_type), std::back_inserter(str_md5));
return true;
}
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐


所有评论(0)