// MD5Test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "MD5Test.h" #include "../lyfzClassicSvc/MD5.h" #include "StringProcess.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 唯一的应用程序对象 CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // 初始化 MFC 并在失败时显示错误 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("错误: MFC 初始化失败\n")); nRetCode = 1; } else { // TODO: 在此处为应用程序的行为编写代码。 CONST TCHAR* pMD5 = NULL; // 默认GB2321的md5值; CMD5 md5((const BYTE*)("1234"), strlen("1234")); pMD5 = md5.GetMD5Digest(); _tprintf(_T("%s\n"), pMD5); // 获取utf8的md5值; CHAR szUtf8[MAX_PATH] = {0}; CHAR szbuffer[MAX_PATH] = "订单号:1779603670"; StringProcess::ascii_to_utf8(szbuffer,szUtf8); md5.SetBYTEText(reinterpret_cast(szUtf8), strlen(szUtf8)); pMD5 = md5.GetMD5Digest(); _tprintf(_T("%s\n"), pMD5); // 获取unicode的md5值; WCHAR szUnicode[MAX_PATH] = L"订单号:1779603670"; BYTE szUN[MAX_PATH] = {0}; INT nBytes = sizeof(WCHAR)*wcslen(szUnicode); memcpy(szUN, szUnicode, nBytes); //INT nChars = strlen((char*)szUN); md5.SetBYTEText(reinterpret_cast(szUN), nBytes); pMD5 = md5.GetMD5Digest(); _tprintf(_T("%s\n"), pMD5); // 获取ascii的md5值; CHAR szAscii[MAX_PATH] = {0}; StringProcess::utf8_to_ascii(szUtf8,szAscii); md5.SetBYTEText(reinterpret_cast(szAscii), strlen(szAscii)); pMD5 = md5.GetMD5Digest(); _tprintf(_T("%s\n"), pMD5); } system("pause"); return nRetCode; }