您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/11/7 0:56:20发布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 }
以上就是分享基于字符串加密的md5算法实例代码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product