时间:2021-05-20
基于字符串加密的MD5算法,VS2008 VC++,多字节编译工程。主要代码如下,实现了ANSI字符串加密与Unicode字符串加密。
运行效果如下:
核心代码:
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 }VS2008 MFC工程源码下载:点击打开链接
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
起因最近遇到一个问题,把某个字符串计算MD5,之后把该字符串加密与MD5一起上传到服务端,服务端解密后重新计算md5发现与上传的MD5不一致,而出问题的字符串中
Md5()加密算法方式:单向加密语法:md5(string$str[,bool$raw_output=false])$str:原始字符串$raw_output:
关于VS2008或VS2005中数据库配置字符串的三种取法VS2008建立Form程序时,如果添加数据源会在配置文件app.config中自动写入连接字符串,这
复制代码代码如下://计算字符串的MD5值publicstringGetMD5(stringsDataIn){MD5CryptoServiceProviderm
Discuz密码加密规则:md5(md5('字符串').'固定字串');固定字符串是在注册用户的时候随机生成的,且保存在数据表p