首页后端开发ASP.NET分享基于字符串加密的MD5算法实例代码

分享基于字符串加密的MD5算法实例代码

时间2024-01-30 13:12:03发布访客分类ASP.NET浏览1083
导读:收集整理的这篇文章主要介绍了分享基于字符串加密的MD5算法实例代码,觉得挺不错的,现在分享给大家,也给大家做个参考。基于字符串加密的MD5算法,VS2008 VC++,多字节编译工程。主要代码如下,实现了ANSI字符串加密与Unicode字...
收集整理的这篇文章主要介绍了分享基于字符串加密的MD5算法实例代码,觉得挺不错的,现在分享给大家,也给大家做个参考。基于字符串加密的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 }
    

以上就是分享基于字符串加密的MD5算法实例代码的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

字符串算法

若转载请注明出处: 分享基于字符串加密的MD5算法实例代码
本文地址: https://pptw.com/jishu/592564.html
javascript find()方法是干什么的 JavaScript中向数组尾部添加元素的方法有哪些

游客 回复需填写必要信息