基于字符串加密的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 }

更多相关文章

  1. asp如何解析json字符串并转化为asp对象
  2. C#实现操作字符串的方法总结
  3. 正则表达式模式匹配字符串基础知识_正则表达式
  4. c/c++字符串函数是什么类型和它是如何转换的?举例说明
  5. 第三章C++:字符串string、向量vector和数组
  6. c语言怎么输出字符串
  7. Perl中如何对混合字符串进行排序?(代码示例)
  8. C++实现逐行读取txt文件中的字符串以及文件文本的复制
  9. 字符串赋值是什么意思

随机推荐

  1. 如何给列表降维?sum()函数的妙用
  2. Python进阶:如何将字符串常量转为变量?
  3. len(x) 击败 x.len(),从内置函数看 Python
  4. sum() 函数性能堪忧,列表降维有何良方?
  5. Linux如何重置root密码-CentOS6,CentOS7,
  6. 遇见一只黑猫,她说程序员都是骗子
  7. 超全的pandas数据分析常用函数总结:上篇
  8. 10 行 Python 代码,批量压缩图片 500 张,简
  9. 聊聊 Python 的内置电池
  10. 一文读懂 Serverless,将配置化思想复用到