md5sum.cpp

来自「MD5加密算法的COM控件以及编译的源码」· C++ 代码 · 共 70 行

CPP
70
字号
/*
 *  MD5 COM component
 *
 *  Copyright (C) 2005  YeeToo Group
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

// MD5Sum.cpp : CMD5Sum 的实现

#include "stdafx.h"
#include "MD5Sum.h"
#include ".\md5sum.h"
#include <comutil.h>

#include "md5module.h"

#pragma comment(lib,"comsupp.lib")

// CMD5Sum


STDMETHODIMP CMD5Sum::MD5Sum(BSTR source, BSTR* result)
{
	CComBSTR bstrResult="";
	
	char *spSource=_com_util::ConvertBSTRToString(source);

	unsigned long int ulngLength=strlen(spSource);
	if(ulngLength<1)
	{
		delete spSource;
		(*result)=bstrResult.Detach();
		return S_OK;
	}

	md5_context ctx;
	unsigned char szmd5sum[16];
	md5_starts(&ctx);
	md5_update(&ctx,(unsigned char *)spSource,ulngLength);
	md5_finish(&ctx,szmd5sum);

	delete spSource;

	char szChar[3];
	for(int i=0;i<16;i++)
	{
		_itoa(szmd5sum[i],szChar,16);
		if(strlen(szChar)==1)
			bstrResult.Append("0");
		bstrResult.Append(szChar);
	}
	
	(*result)=bstrResult.Detach();

	return S_OK;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?