运行效果如下:
核心代码:
voID CEncryptByMd5Dlg::OnbuttonOk() { // Todo: Add your control notification handler code here UpdateData(true); unsigned int len=0; char *cTemp =NulL; if(m_bType==0) { len=m_sText.GetLength(); cTemp=(char*)(LPCTSTR)m_sText; } else { len=CStringW(m_sText).GetLength()*2; cTemp=(char*)ANSI2UNICODE(m_sText); } char *cIDentity; CMd5A md5; cIDentity = md5.mdstring(cTemp,len); m_sEncrypt = CString(cIDentity); if(m_bUpper==TRUE) { m_sEncrypt.MakeUpper(); } else { m_sEncrypt.MakeLower(); } UpdateData(false); } voID CEncryptByMd5Dlg::OnBnClickedBtnCompare() { // Todo: Add your control notification handler code here UpdateData(true); if(m_sEncrypt==m_szMD5_2) { MessageBox(_T("密文比较结果相同!"),_T("比较相同"),MB_OK|MB_ICONinformatION); } else { MessageBox(_T("密文比较结果失败!"),_T("比较不同"),MB_OK|MB_ICONERROR); } UpdateData(FALSE); } voID CEncryptByMd5Dlg::OnEnChangeEdit1() { // Todo: If this is a RICHEDIT control, the control will not // send this notification unless you overrIDe the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. OnbuttonOk(); // Todo: Add your control notification handler code here } char * CEncryptByMd5Dlg::Unicode2ANSI(CString strSource) { if (strSource.IsEmpty()) return NulL; char *pBuffer = NulL; int nBufferSize = 0; #ifdef _UNICODE nBufferSize = WIDeCharToMultiByte(CP_ACP, 0, (LPCTSTR)strSource, -1, NulL, 0, NulL, NulL) + 1; pBuffer = new char[nBufferSize]; memset(pBuffer, 0, sizeof(char)*nBufferSize); WIDeCharToMultiByte(CP_ACP, 0, (LPCTSTR)strSource, -1, pBuffer, nBufferSize, NulL, NulL); #else nBufferSize = strSource.GetLength() + 1; pBuffer = new char[nBufferSize]; memset(pBuffer, 0, sizeof(char)*nBufferSize); strcpy_s(pBuffer, nBufferSize, (LPCTSTR)strSource); #endif return pBuffer; } wchar_t * CEncryptByMd5Dlg::ANSI2UNICODE(CString pData) { int nLength = MultiBytetoWIDeChar(CP_ACP, 0, pData, -1, NulL, 0); wchar_t *pwBuffer = new wchar_t[nLength + 1]; memset(pwBuffer, 0, sizeof(wchar_t)*(nLength + 1)); MultiBytetoWIDeChar(CP_ACP, 0, pData, -1, pwBuffer, nLength); return pwBuffer; } voID CEncryptByMd5Dlg::OnBnClickedCheckUpper() { OnbuttonOk(); // Todo: Add your control notification handler code here } voID CEncryptByMd5Dlg::OnBnClickedRadio1() { OnbuttonOk(); // Todo: Add your control notification handler code here } voID CEncryptByMd5Dlg::OnBnClickedRadio2() { OnbuttonOk(); // Todo: Add your control notification handler code here }总结
以上是内存溢出为你收集整理的分享基于字符串加密的MD5算法实例代码全部内容,希望文章能够帮你解决分享基于字符串加密的MD5算法实例代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)