/** Auxilary function should be called only when we need to generate hash values from the screen and returns its hex format. @param aHexString the output MD5 hash hex string obtained from iBitmapDevice */ EXPORT_C void CTHashReferenceImages::GenerateHashAndReturnInHexFormatL(TDes &aHexString) { TInt bufLen = CFbsBitmap::ScanLineLength(iBitmapDevice->SizeInPixels().iWidth, iBitmapDevice->DisplayMode()); RBuf8 buff; buff.CreateL(bufLen); CleanupClosePushL(buff); CMD5 *md = CMD5::NewL(); CleanupStack::PushL(md); for (TPoint pos(0, 0); pos.iY < iBitmapDevice->SizeInPixels().iHeight; pos.iY++) { iBitmapDevice->GetScanLine(buff,pos,iBitmapDevice->SizeInPixels().iWidth,iBitmapDevice->DisplayMode()); md->Update(buff); } TBuf8<KLengthOfHashValue> hashString; //md will be reset after calling CMD5::Final() as Final will call Reset. hashString.Copy(md->Final()); aHexString.Zero(); for(TInt icount=0; icount < hashString.Length(); icount++) { aHexString.AppendNumFixedWidth(hashString[icount], EHex, 4); } CleanupStack::PopAndDestroy(2, &buff); }
void CRegisterDlg::OnOK() { CMD5 crypt; CString strTemp; UpdateData(); m_strName.TrimLeft(); m_strName.TrimRight(); m_strKey.TrimLeft(); m_strKey.TrimRight(); strTemp = m_strName.Left(32); strTemp += MD5_HASH_KEY; crypt.setPlainText(strTemp); if (!m_strKey.Compare(crypt.getMD5Digest())) { CWinApp* pApp = AfxGetApp(); UpdateData(); pApp->WriteProfileString("Options", "Name", m_strName); pApp->WriteProfileString("Options", "Key", m_strKey); MessageBox("Registration key accepted! Thank you for registering.", "Success"); } else { MessageBox("Invalid registration key. Please try again.", "Error"); return; } CDialog::OnOK(); }
bool CMD5::operator==(const CMD5& rhs) { if (!isDigestValid() || !rhs.isDigestValid()) { return false; } const char* rhsDigest = rhs.getMD5Digest(); int result = strncmp(m_digestString, rhsDigest , 33); return (result == 0); }