计算字符串的md5值

📅 发布时间:2026/7/6 8:52:41 👁️ 浏览次数:
计算字符串的md5值
调用openssl的接口实现代码#include "EncryUtil.h" #include iostream #include openssl/md5.h bool EncryUtil::MD5_Calculate(const char *pContent, unsigned int nLen, std::string strMd5) { strMd5.clear(); if (pContent == nullptr || nLen == 0) { return false; } unsigned char d[16] = { 0 }; MD5_CTX ctx; MD5_Init(ctx); MD5_Update(ctx, pContent, nLen); MD5_Final(d, ctx); char md5[33] = {0}; for (int i = 0; i 16; ++i) { snprintf(md5 + (i * 2), 32, "%02x", d[i]); } md5[32] = 0; strMd5 = md5; return true; }调用示例// 调用示例 // 计算字符串的MD5值 std::string s