1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include "postal.h"
#include "cmd5.h"
#include <stdio.h>
Cmd5::Cmd5()
{
init();
}
void Cmd5::init()
{
#ifdef USE_OPENSSL
MD5_Init(&m_context);
#else
MD5Init(&m_context);
#endif
}
void Cmd5::getSum(char *buf)
{
#ifdef USE_OPENSSL
MD5_Final((unsigned char *)buf, &m_context);
#else
MD5Final((unsigned char *)buf, &m_context);
#endif
}
// get the sum into a string reference
string Cmd5::getSum()
{
unsigned char output[16];
getSum((char *)output);
char str_output[33];
for(int i = 0; i < 16; i++)
{
sprintf(&str_output[2 * i], "%02x", (int)output[i]);
}
return str_output;
}
void Cmd5::addData(const char *buf, size_t bytes)
{
#ifdef USE_OPENSSL
MD5_Update(&m_context, (const unsigned char *)buf, bytes);
#else
MD5Update(&m_context, (const unsigned char *)buf, bytes);
#endif
}
void Cmd5::addData(const string &buf)
{
addData((const char *)buf.c_str(), buf.size());
}
|