cocos2d-x 文件MD5校验(10)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
p> *****************************************************************************************/
p>void CMD5Checksum::DWordToByte(BYTE* Output, DWORD* Input, UINT nLength )
p>{
p> //entry invariants
p> ASSERT( nLength % 4 == 0 );
p> //ASSERT( AfxIsValidAddress(Output, nLength, TRUE) );
p> //ASSERT( AfxIsValidAddress(Input, nLength/4, FALSE) );
p>
p> //transfer the data by shifting and copying
p> UINT i = 0;
p> UINT j = 0;
p> for ( ; j < nLength; i++, j += 4)
p> {
p> Output[j] = (UCHAR)(Input[i] & 0xff );
p> Output[j+1] = (UCHAR)((Input[i] >> 8) & 0xff);
p> Output[j+2] = (UCHAR)((Input[i] >> 16) & 0xff);
p> Output[j+3] = (UCHAR)((Input[i] >> 24) & 0xff);
p> }
p>}
p>
p>
p>/*****************************************************************************************
p> FUNCTION: CMD5Checksum::Final
p> DETAILS: protected
p> DESCRIPTION: Implementation of main MD5 checksum algorithm; ends the checksum calculation.
p> RETURNS: std::string : the final hexadecimal MD5 checksum result
p> ARGUMENTS: None
p> NOTES: Performs the final MD5 checksum calculation ('Update' does most of the work,
p> this function just finishes the calculation.)
p> *****************************************************************************************/
p>std::string CMD5Checksum::Final()
p>{
p> //Save number of bits
p> BYTE Bits[8];
p> DWordToByte( Bits, m_nCount, 8 );
p>
p> //Pad out to 56 mod 64.
p> UINT nIndex = (UINT)((m_nCount[0] >> 3) & 0x3f);
p> UINT nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex);
p> Update( PADDING, nPadLen );
p>
p> //Append length (before padding)
p> Update( Bits, 8 );
p>
p> //Store final state in 'lpszMD5'
p> const int nMD5Size = 16;
p> unsigned char lpszMD5[ nMD5Size ];
p> DWordToByte( lpszMD5, m_lMD5, nMD5Size );
p>
p> //Convert the hexadecimal checksum to a std::string
p> std::string strMD5;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>