VC++ 字符串String MD5計(jì)算小工具 VS2008工程
基于字符串加密的MD5算法,VS2008 VC++,多字節(jié)編譯工程。主要代碼如下,實(shí)現(xiàn)了ANSI字符串加密與Unicode字符串加密。
運(yùn)行效果如下:

核心代碼:
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("密文比較結(jié)果相同!"),_T("比較相同"),MB_OK|MB_ICONINFORMATION);
}
else
{
MessageBox(_T("密文比較結(jié)果失??!"),_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
}
VS2008 MFC工程源碼下載:點(diǎn)擊打開(kāi)鏈接
相關(guān)文章
C++實(shí)現(xiàn)LeetCode(48.旋轉(zhuǎn)圖像)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(48.旋轉(zhuǎn)圖像),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)與算法之鏈表(一)
鏈表是線性表的鏈?zhǔn)酱鎯?chǔ)方式。鏈表的內(nèi)存是不連續(xù)的,前一個(gè)元素存儲(chǔ)地址的下一個(gè)地址中存儲(chǔ)的不一定是下一個(gè)元素。小編今天就將帶大家深入了解一下鏈表,快來(lái)學(xué)習(xí)吧2021-12-12
QT中進(jìn)程的創(chuàng)建實(shí)現(xiàn)
本文主要介紹了QT中進(jìn)程的創(chuàng)建實(shí)現(xiàn),詳細(xì)介紹了創(chuàng)建進(jìn)程的整個(gè)過(guò)程,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2023-08-08
簡(jiǎn)單掌握C++編程中的while與do-while循環(huán)語(yǔ)句使用
這篇文章主要介紹了C++編程中的while與do-while循環(huán)語(yǔ)句使用,區(qū)別就是while是先判斷再執(zhí)行,而do-while是先執(zhí)行再判斷,需要的朋友可以參考下2016-01-01
C++設(shè)計(jì)模式中控制反轉(zhuǎn)與依賴(lài)注入淺析
這篇文章主要介紹了C++設(shè)計(jì)模式中控制反轉(zhuǎn)與依賴(lài)注入,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-01-01
基于QT實(shí)現(xiàn)顯示OpenCV讀取的圖片
OpenCV自帶了一部分常用的GUI功能,但是更多的圖像處理功能需要其他GUI框架來(lái)輔助實(shí)現(xiàn),本文將通過(guò)QT來(lái)顯示OpenCV讀取的圖片,需要的可以參考一下2022-11-11

