Share the MD5 algorithm instance code based on string encryption

Source: Internet
Author: User
MD5 algorithm based on string encryption, VS2008 VC + +, multi-byte compilation project. The main code is as follows, which implements ANSI string encryption and Unicode string encryption.

The results are as follows:

Core code:

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 () * *;   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 Updatedat   A (true); if (m_sencrypt==m_szmd5_2) {MessageBox (_t ("Ciphertext comparison results same!"), _t ("compare Same"), mb_ok|   Mb_iconinformation); } else {MessageBox (_t ("Ciphertext comparison result failed! "), _t (" compare different "), mb_ok|   MB_ICONERROR); } updatedata (FALSE); } void Cencryptbymd5dlg::onenchangeedit1 () {//Todo:if This is a RICHEDIT control, theControl won't//send this notification unless your override the CDialog::OnInitDialog ()//function and call Criche Ditctrl ().   SetEventMask ()//with the ENM_CHANGE flag ORed into the mask.   Onbuttonok (); Todo:add your control notification handler code here} char * Cencryptbymd5dlg::unicode2ansi (CString strsource) {i   F (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}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.