VC++ 字符串String MD5計(jì)算小工具 VS2008工程
更新時(shí)間:2017年07月23日 10:56:55 投稿:mdxy-dxy
基于字符串加密的MD5算法,VS2008 VC++,多字節(jié)編譯工程。主要代碼如下,實(shí)現(xiàn)了ANSI字符串加密與Unicode字符串加密,需要的朋友可以參考下
基于字符串加密的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)擊打開鏈接
相關(guān)文章
C語言實(shí)現(xiàn)數(shù)獨(dú)輔助器(附源碼)
數(shù)獨(dú)是源自瑞士的一種數(shù)學(xué)游戲。是一種運(yùn)用紙、筆進(jìn)行演算的邏輯游戲。本文將利用C語言制作一個(gè)數(shù)獨(dú)輔助器,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-01-01
c語言?數(shù)據(jù)存儲(chǔ)與原碼?反碼?補(bǔ)碼詳細(xì)解析
不知道你是否和我一樣好奇,學(xué)習(xí)編程語言的同時(shí)想,各個(gè)數(shù)據(jù)類型是怎樣在我們的內(nèi)存中儲(chǔ)存的呢,如果你仔細(xì)深入了解的話,你會(huì)了解其中的樂趣,了解科學(xué)家們的偉大,了解c語言2022-02-02
C語言數(shù)組入門之?dāng)?shù)組的聲明與二維數(shù)組的模擬
這篇文章主要介紹了C語言數(shù)組入門之?dāng)?shù)組的聲明與二維數(shù)組的模擬,數(shù)組學(xué)習(xí)的同時(shí)也要相應(yīng)理解C語言指針的作用,需要的朋友可以參考下2015-12-12
基于C++實(shí)現(xiàn)的各種內(nèi)部排序算法匯總
這篇文章主要介紹了基于C++實(shí)現(xiàn)的各種內(nèi)部排序算法,非常經(jīng)典,需要的朋友可以參考下2014-08-08

