MD5Test.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // MD5Test.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "MD5Test.h"
  5. #include "../lyfzClassicSvc/MD5.h"
  6. #include "StringProcess.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // 唯一的应用程序对象
  11. CWinApp theApp;
  12. using namespace std;
  13. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  14. {
  15. int nRetCode = 0;
  16. // 初始化 MFC 并在失败时显示错误
  17. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  18. {
  19. // TODO: 更改错误代码以符合您的需要
  20. _tprintf(_T("错误: MFC 初始化失败\n"));
  21. nRetCode = 1;
  22. }
  23. else
  24. {
  25. // TODO: 在此处为应用程序的行为编写代码。
  26. CONST TCHAR* pMD5 = NULL;
  27. // 默认GB2321的md5值;
  28. CMD5 md5((const BYTE*)("1234"), strlen("1234"));
  29. pMD5 = md5.GetMD5Digest();
  30. _tprintf(_T("%s\n"), pMD5);
  31. // 获取utf8的md5值;
  32. CHAR szUtf8[MAX_PATH] = {0};
  33. CHAR szbuffer[MAX_PATH] = "订单号:1779603670";
  34. StringProcess::ascii_to_utf8(szbuffer,szUtf8);
  35. md5.SetBYTEText(reinterpret_cast<BYTE*>(szUtf8), strlen(szUtf8));
  36. pMD5 = md5.GetMD5Digest();
  37. _tprintf(_T("%s\n"), pMD5);
  38. // 获取unicode的md5值;
  39. WCHAR szUnicode[MAX_PATH] = L"订单号:1779603670";
  40. BYTE szUN[MAX_PATH] = {0};
  41. INT nBytes = sizeof(WCHAR)*wcslen(szUnicode);
  42. memcpy(szUN, szUnicode, nBytes);
  43. //INT nChars = strlen((char*)szUN);
  44. md5.SetBYTEText(reinterpret_cast<BYTE*>(szUN), nBytes);
  45. pMD5 = md5.GetMD5Digest();
  46. _tprintf(_T("%s\n"), pMD5);
  47. // 获取ascii的md5值;
  48. CHAR szAscii[MAX_PATH] = {0};
  49. StringProcess::utf8_to_ascii(szUtf8,szAscii);
  50. md5.SetBYTEText(reinterpret_cast<BYTE*>(szAscii), strlen(szAscii));
  51. pMD5 = md5.GetMD5Digest();
  52. _tprintf(_T("%s\n"), pMD5);
  53. }
  54. system("pause");
  55. return nRetCode;
  56. }