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}