原来文本为abcdefg str取原文本的前四位也就是ABCD len为源文本长度也就是7 Strings::Md5 (str, len, 32); std::string Md5 (const void* str, size_t length, size_t block_length){ MD5_CTX md5_ctx = { 0 }; unsigned char sign[16] = { 0 }; if (length){ MD5_Init (&md5_ctx); MD5_Update (&md5_ctx, str, length); MD5_Final (sign, &md5_ctx); }
if (block_length){ return std::string (HexStrFormByteArray (sign, 16), 0, block_length); } else{
return std::string (HexStrFormByteArray (sign, 16), 0); } } std::string HexStrFormByteArray (unsigned char *data, int len){ std::stringstream ss; ss << std::hex << std::setw (2) << std::setfill ( for (int i (0); i < len; ++i){ ss << (int)data[i] << std::setw (2) << std::setfill ( } return std::string (ss.str ()); } 最后加密的结果为abc903f9f7fd61fe6cb9dd0d02a869bb 希望帮忙翻译成易 直接用易的md5加密结果不一样
|