cocos2d-x 文件MD5校验(4)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
p>
p>private:
p> BYTE m_lpszBuffer[64]; //input buffer
p> ULONG m_nCount[2]; //number of bits, modulo 2^64 (lsb first)
p> ULONG m_lMD5[4]; //MD5 checksum
p>};
p>
p>#endif /* defined(__CMD5Checksum__) */
p>
p>[cpp]
p>//
p>// MD5ChecksumDefines.cpp
p>//
p>
p>#include "MD5ChecksumDefines.h"
p>#include "CMD5Checksum.h"
p>
p>#ifdef _DEBUG
p>#undef THIS_FILE
p>static char THIS_FILE[]=__FILE__;
p>#define new DEBUG_NEW
p>#endif
p>
p>
p>/*****************************************************************************************
p>
p> *****************************************************************************************/
p>std::string CMD5Checksum::GetMD5(const std::string& strFilePath)
p>{
p> FILE *file;
p> file = fopen(strFilePath.c_str(), "r");
p> if(!file)
p> return "";
p> CMD5Checksum MD5Checksum; //checksum object
p> int nLength = 0; //number of bytes read from the file
p> const int nBufferSize = 1024; //checksum the file in blocks of 1024 bytes
p> BYTE Buffer[nBufferSize]; //buffer for data read from the file
p>
p> //checksum the file in blocks of 1024 bytes
p> while ((nLength =fread(Buffer, 1, nBufferSize, file)) > 0 )
p> {
p> MD5Checksum.Update( Buffer, nLength );
p> }
p>
p> fclose(file);
p>
p> //finalise the checksum and return it
p> return MD5Checksum.Final();
p>
p>}
p>
p>/*****************************************************************************************
p> FUNCTION: CMD5Checksum::RotateLeft
p> DETAILS: private
p> DESCRIPTION: Rotates the bits in a 32 bit DWORD left by a specified amount
p> RETURNS: The rotated DWORD
p> ARGUMENTS: DWORD x : the value to be rotated
p> int n : the number of bits to rotate by
p> *****************************************************************************************/
p>DWORD CMD5Checksum::RotateLeft(DWORD x, int n)
p>{
p> //check that DWORD is 4 bytes long - true in Visual C++ 6 and 32 bit Windows
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>