// OpenSslAppFrame.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "OpenSslAppFrame.h"#include //OpenSSL版本0.9.8a, 换成别的版本需要更换 ///<../../../bin中的Dll> ///<../../../inc中的.h> ///<../../../lib中的.lib>//头缺的加在这里#include #include #include #include //库全了,就这2个#pragma comment(lib, "libeay32.lib")#pragma comment(lib, "ssleay32.lib")#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// The one and only application objectCWinApp theApp;using namespace std;void OpenSslBegin();//OpenSSL初始化void OpenSslEnd();//OpenSSL反初始化int fnOpenSSLProcess();//OpenSSL的框架函数int fnMyTestOnOpenSSL();//我们具体的OpenSSL代码写在这里int fnSha1Demo();//Sha1演示int fnBigFileMd5Test();//测试文件Md5的时间性能//toolsint FnPrintBuffer(PCHAR pcPrefix, PBYTE pbcBuffer, DWORD dwLenBuffer);static DWORD dwTimeBegin = 0; static DWORD dwTimeEnd = 0; void TimeLogBegin(); void TimeLogEnd(); void showTimeLog();int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){ int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr <<_T("Fatal Error: MFC initialization failed") <>读入'f://BigFile.dat'/n"); TimeLogBegin(); if(1) { CFile file; if(!file.Open("f://BigFile.dat", CFile::modeReadWrite | CFile::typeBinary)) return S_FALSE; dwLenFile = file.GetLength(); printf("文件size = %d/n", dwLenFile); pBufFile = new BYTE[dwLenFile]; _ASSERT(pBufFile); UINT uNeedRdBack = dwLenFile; UINT uRdBack = 1; DWORD dwOffsetFileRd = 0; while(uRdBack > 0) { //开发机配置, 2G内存, XpSp3 //1G的文件, file.Read能一次搞定 uRdBack = file.Read(pBufFile + dwOffsetFileRd, uNeedRdBack); if(uRdBack == uNeedRdBack) break;//一次搞定, 读了几秒的样子 else { dwOffsetFileRd = uRdBack; uNeedRdBack -= uRdBack; } } file.Close(); } TimeLogEnd(); showTimeLog(); //计算整个文件做MD5的时间 printf(">>计算MD5'f://BigFile.dat/n'"); TimeLogBegin(); if(1) { BYTE Md5Out[MD5_LBLOCK]; memset(Md5Out, 0, MD5_LBLOCK); PBYTE pBufMd5Out = NULL; pBufMd5Out = MD5(pBufFile, dwLenFile, Md5Out); if(pBufMd5Out) { FnPrintBuffer("Md5计算成功", Md5Out, MD5_LBLOCK); } else { printf("Md5失败/n"); } } TimeLogEnd(); showTimeLog(); //计算文件分成1M一块做MD5的时间 if(pBufFile) { delete pBufFile; pBufFile = NULL; } return S_OK; }int fnSha1Demo(){ int n = 0; const int const nLenMd = 20;//sha1摘要长度总是20 PBYTE md = new BYTE[nLenMd]; memset(md, 0, nLenMd); PCHAR const pMsgIn = "/'做摘要的数据可以是二进制的流, 这里用明文代替./'"; DWORD dwSizeSha1Src = strlen(pMsgIn); PBYTE pSha1Src = new BYTE[dwSizeSha1Src + 1]; _ASSERT(pSha1Src); pSha1Src[dwSizeSha1Src] = '/0'; memcpy(pSha1Src, pMsgIn, dwSizeSha1Src); //unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); SHA1(pSha1Src, dwSizeSha1Src, md); printf("原文:[%s]/n", pSha1Src); printf("原文Sha1摘要:["); for(n = 0; n