acl/lib_acl_cpp/samples/md5/main.cpp

78 lines
1.6 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
// md5.cpp : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨Ӧ<CCA8>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ㡣
//
#include "stdafx.h"
#include <assert.h>
#include "md5_c.h"
int main()
{
const char* s = "<EFBFBD>й<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
const char* key = "zsxxsz";
char buf1[33], buf2[33];
acl::md5::md5_string(s, strlen(s), key, strlen(key),
buf1, sizeof(buf1));
printf("first md5: %s\r\n", buf1);
md5_string(s, key, strlen(key), buf2, sizeof(buf2));
printf("second md5: %s\r\n", buf2);
assert(strcmp(buf1, buf2) == 0);
2015-01-30 22:58:13 +08:00
/////////////////////////////////////////////////////////////////////
acl::md5 md5;
s = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
md5.update(s, strlen(s));
md5.finish();
acl::safe_snprintf(buf1, sizeof(buf1), "%s", md5.get_string());
md5.reset();
char ch;
size_t len = strlen(s);
for (size_t i = 0; i < len; i++)
{
ch = s[i];
md5.update(&ch, 1);
}
md5.finish();
acl::safe_snprintf(buf2, sizeof(buf2), "%s", md5.get_string());
if (strcmp(buf1, buf2) == 0)
printf("OK: %s\r\n", buf1);
else
printf("error, buf1: %s, buf2: %s\r\n", buf1, buf2);
/////////////////////////////////////////////////////////////////////
md5.reset();
len = 1024000;
char* buf = (char*) malloc(len);
for (size_t i = 0; i < len; i++)
{
ch = i % 255;
buf[i] = ch;
md5.update(&ch, 1);
}
md5.finish();
acl::safe_snprintf(buf1, sizeof(buf1), "%s", md5.get_string());
md5.reset();
md5.update(buf, len);
md5.finish();
acl::safe_snprintf(buf2, sizeof(buf2), "%s", md5.get_string());
if (strcmp(buf1, buf2) == 0)
printf("OK2: %s\r\n", buf1);
else
printf("error, buf1: %s, buf2: %s\r\n", buf1, buf2);
2014-11-19 00:25:21 +08:00
#ifdef WIN32
getchar();
#endif
return 0;
}