读书人

怎样计算文件的MD5 校验校值?解决思路

发布时间: 2012-03-15 11:50:39 作者: rapoo

怎样计算文件的MD5 校验校值??
怎么计算一个文件信息的MD5值来用于出错检测.在Win32和WinCE中有没有这样的API函数??

[解决办法]
CryptCreateHash CryptHashData .....
WIN CryptoAPI 极端无趣, 还不如用些开源库快捷方便, 比如 openssl 啥的 ..
[解决办法]
http://www.ietf.org/rfc/rfc1321.txt
[解决办法]
你在百度搜索
MD5ChecksumDefines.h
MD5Checksum.h
MD5Checksum.cpp
这三个文件,是个MD5的c++实现,可以取得字符串、文件的MD5值
/*****************************************************************************************
FUNCTION: CMD5Checksum::GetMD5
DETAILS: static, public
DESCRIPTION: Gets the MD5 checksum for a specified file
RETURNS: CString : the hexadecimal MD5 checksum for the specified file
ARGUMENTS: CString& strFilePath : the full pathname of the specified file
NOTES: Provides an interface to the CMD5Checksum class. 'strFilePath ' name should
hold the full pathname of the file, eg C:\My Documents\Arcticle.txt.
NB. If any problems occur with opening or reading this file, a CFileException
will be thrown; callers of this function should be ready to catch this
exception.
*****************************************************************************************/
[解决办法]
唉,仔细看看,多用google,并不是什么事别人都能帮你的


a piece from:
http://www.ietf.org/rfc/rfc1321.txt
----------------------------------


static void MDFile (filename)
char *filename;
{
FILE *file;
MD_CTX context;
int len;
unsigned char buffer[1024], digest[16];

if ((file = fopen (filename, "rb ")) == NULL)
printf ( "%s can 't be opened\n ", filename);

else {
MDInit (&context);
while (len = fread (buffer, 1, 1024, file))
MDUpdate (&context, buffer, len);
MDFinal (digest, &context);

fclose (file);

printf ( "MD%d (%s) = ", MD, filename);
MDPrint (digest);
printf ( "\n ");
}
}

读书人网 >C语言

热点推荐