利用crypto++库,实现计算string的md5值

#include <cryptopp/hex.h>
#include <cryptopp/files.h>
#include <cryptopp/md5.h>
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 
/*
 * Description: to calculate the hash of the message, and return it(string).
 * Input:
 *     message: need to calculate its hash value
 * Output:
 *     return the hash value(string) of the message.
 */
string md5_string(const string & message)
{
    string digest;
    Weak::MD5 md5;
    StringSource(message, true,
                new HashFilter(md5, new HexEncoder(new StringSink(digest))));
    return digest;
}

你可能感兴趣的:(利用crypto++库,实现计算string的md5值)