|
Crypt Library Demo 1.00
|
#include <CryptLibraryDemoDlg.h>
Public Types | |
| enum | { IDD = IDD_CRYPTLIBRARYDEMO_DIALOG } |
Public Member Functions | |
| CCryptLibraryDemoDlg (CWnd *pParent=NULL) | |
| virtual BOOL | OnInitDialog () |
| afx_msg void | OnSysCommand (UINT nID, LPARAM lParam) |
| afx_msg void | OnPaint () |
| afx_msg HCURSOR | OnQueryDragIcon () |
| afx_msg void | OnBnClickedSelect () |
| afx_msg void | OnBnClickedCompute () |
| afx_msg void | OnBnClickedInputfile () |
| afx_msg void | OnBnClickedOutputfile () |
| afx_msg void | OnBnClickedEncrypt () |
| afx_msg void | OnBnClickedDecrypt () |
Protected Member Functions | |
| virtual void | DoDataExchange (CDataExchange *pDX) |
Protected Attributes | |
| HICON | m_hIcon |
| CButton | m_btnCompute |
| CButton | m_btnEncrypt |
| CButton | m_btnDecrypt |
| CEdit | m_editFilename |
| CEdit | m_editChecksum |
| CEdit | m_editInputName |
| CEdit | m_editOutputName |
| CString | m_strFilename |
| CString | m_strChecksum |
| CString | m_strInputName |
| CString | m_strOutputName |
Definition at line 24 of file CryptLibraryDemoDlg.h.
| anonymous enum |
Definition at line 31 of file CryptLibraryDemoDlg.h.
{ IDD = IDD_CRYPTLIBRARYDEMO_DIALOG };
| CCryptLibraryDemoDlg::CCryptLibraryDemoDlg | ( | CWnd * | pParent = NULL | ) |
Definition at line 125 of file CryptLibraryDemoDlg.cpp.
: CDialog(CCryptLibraryDemoDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
| void CCryptLibraryDemoDlg::DoDataExchange | ( | CDataExchange * | pDX | ) | [protected, virtual] |
Definition at line 131 of file CryptLibraryDemoDlg.cpp.
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FILENAME, m_editFilename);
DDX_Control(pDX, IDC_CHECKSUM, m_editChecksum);
DDX_Control(pDX, IDC_INPUTNAME, m_editInputName);
DDX_Control(pDX, IDC_OUTPUTNAME, m_editOutputName);
DDX_Control(pDX, IDC_COMPUTE, m_btnCompute);
DDX_Control(pDX, IDC_ENCRYPT, m_btnEncrypt);
DDX_Control(pDX, IDC_DECRYPT, m_btnDecrypt);
}
| void CCryptLibraryDemoDlg::OnBnClickedCompute | ( | ) |
Definition at line 282 of file CryptLibraryDemoDlg.cpp.
{
CString strResult;
if (!m_strFilename.IsEmpty())
{
if (GetChecksumFile(CALG_MD5, strResult, m_strFilename))
{
m_editChecksum.SetWindowText(strResult);
MessageBox(_T("MD5 checksum of selected file is ready!"), _T("Crypt Library Demo"), MB_OK);
}
}
}

| void CCryptLibraryDemoDlg::OnBnClickedDecrypt | ( | ) |
Definition at line 337 of file CryptLibraryDemoDlg.cpp.
{
CString strSecretKey = GetComputerID();
LPBYTE lpszSecretKey = (LPBYTE)(LPCTSTR)strSecretKey;
DWORD dwSecretKey = (strSecretKey.GetLength() + 1) * sizeof(TCHAR);
if (!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty())
{
if (EncryptFile(CALG_RC4, m_strOutputName, m_strInputName, lpszSecretKey, dwSecretKey))
{
MessageBox(_T("The file have been successfully decrypted!"), _T("Crypt Library Demo"), MB_OK);
}
}
}

| void CCryptLibraryDemoDlg::OnBnClickedEncrypt | ( | ) |
Definition at line 323 of file CryptLibraryDemoDlg.cpp.
{
CString strSecretKey = GetComputerID();
LPBYTE lpszSecretKey = (LPBYTE)(LPCTSTR)strSecretKey;
DWORD dwSecretKey = (strSecretKey.GetLength() + 1) * sizeof(TCHAR);
if (!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty())
{
if (EncryptFile(CALG_RC4, m_strOutputName, m_strInputName, lpszSecretKey, dwSecretKey))
{
MessageBox(_T("The file have been successfully encrypted!"), _T("Crypt Library Demo"), MB_OK);
}
}
}

| void CCryptLibraryDemoDlg::OnBnClickedInputfile | ( | ) |
Definition at line 295 of file CryptLibraryDemoDlg.cpp.
{
DWORD dwFlags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_LONGNAMES;
LPCTSTR lpszFilter = _T("All files (*.*)|*.*\0");
CFileDialog pFileDialog(TRUE, NULL, NULL, dwFlags, lpszFilter, this);
if (pFileDialog.DoModal() == IDOK)
{
m_strInputName = pFileDialog.GetPathName();
m_editInputName.SetWindowText(m_strInputName);
m_btnEncrypt.EnableWindow(!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty());
m_btnDecrypt.EnableWindow(!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty());
}
}
| void CCryptLibraryDemoDlg::OnBnClickedOutputfile | ( | ) |
Definition at line 309 of file CryptLibraryDemoDlg.cpp.
{
DWORD dwFlags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_LONGNAMES;
LPCTSTR lpszFilter = _T("All files (*.*)|*.*\0");
CFileDialog pFileDialog(FALSE, NULL, NULL, dwFlags, lpszFilter, this);
if (pFileDialog.DoModal() == IDOK)
{
m_strOutputName = pFileDialog.GetPathName();
m_editOutputName.SetWindowText(m_strOutputName);
m_btnEncrypt.EnableWindow(!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty());
m_btnDecrypt.EnableWindow(!m_strInputName.IsEmpty() && !m_strOutputName.IsEmpty());
}
}
| void CCryptLibraryDemoDlg::OnBnClickedSelect | ( | ) |
Definition at line 269 of file CryptLibraryDemoDlg.cpp.
{
DWORD dwFlags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_LONGNAMES;
LPCTSTR lpszFilter = _T("All files (*.*)|*.*\0");
CFileDialog pFileDialog(TRUE, NULL, NULL, dwFlags, lpszFilter, this);
if (pFileDialog.DoModal() == IDOK)
{
m_strFilename = pFileDialog.GetPathName();
m_editFilename.SetWindowText(m_strFilename);
m_btnCompute.EnableWindow(!m_strFilename.IsEmpty());
}
}
| BOOL CCryptLibraryDemoDlg::OnInitDialog | ( | ) | [virtual] |
Definition at line 160 of file CryptLibraryDemoDlg.cpp.
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
#ifdef _DEBUG
CString strBuffer1 = _T("abc"), strResult1;
VERIFY(GetChecksumString(CALG_MD5, strResult1, strBuffer1));
TRACE(_T("MD5(%s) => %s\n"), strBuffer1, strResult1);
CString strBuffer2 = _T("abc"), strResult2;
VERIFY(GetChecksumFile(CALG_SHA1, strResult2, _T("D:\\AddressBook.csv")));
TRACE(_T("SHA1(%s) => %s\n"), strBuffer2, strResult2);
CString strSecretKey = GetComputerID();
LPBYTE lpszSecretKey = (LPBYTE)(LPCTSTR)strSecretKey;
DWORD dwSecretKey = (strSecretKey.GetLength() + 1) * sizeof(TCHAR);
CString strFilename = _T("D:\\AddressBook.csv");
CString strEncrypt = _T("D:\\AddressBook.rc4");
CString strDecrypt = _T("D:\\AddressBook.txt");
VERIFY(EncryptFile(CALG_RC4, strEncrypt, strFilename, lpszSecretKey, dwSecretKey));
VERIFY(DecryptFile(CALG_RC4, strDecrypt, strEncrypt, lpszSecretKey, dwSecretKey));
#endif
CRect rectCryptLibraryDemo;
GetClientRect(&rectCryptLibraryDemo);
TRACE(_T("[CCryptLibraryDemoDlg] Width = %d, Height = %d\n"),
rectCryptLibraryDemo.Width(), rectCryptLibraryDemo.Height());
m_btnCompute.EnableWindow(FALSE);
m_btnEncrypt.EnableWindow(FALSE);
m_btnDecrypt.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}

| void CCryptLibraryDemoDlg::OnPaint | ( | ) |
Definition at line 237 of file CryptLibraryDemoDlg.cpp.
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
| HCURSOR CCryptLibraryDemoDlg::OnQueryDragIcon | ( | ) |
Definition at line 264 of file CryptLibraryDemoDlg.cpp.
{
return static_cast<HCURSOR>(m_hIcon);
}
| void CCryptLibraryDemoDlg::OnSysCommand | ( | UINT | nID, |
| LPARAM | lParam | ||
| ) |
Definition at line 220 of file CryptLibraryDemoDlg.cpp.
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
CButton CCryptLibraryDemoDlg::m_btnCompute [protected] |
Definition at line 53 of file CryptLibraryDemoDlg.h.
CButton CCryptLibraryDemoDlg::m_btnDecrypt [protected] |
Definition at line 55 of file CryptLibraryDemoDlg.h.
CButton CCryptLibraryDemoDlg::m_btnEncrypt [protected] |
Definition at line 54 of file CryptLibraryDemoDlg.h.
CEdit CCryptLibraryDemoDlg::m_editChecksum [protected] |
Definition at line 57 of file CryptLibraryDemoDlg.h.
CEdit CCryptLibraryDemoDlg::m_editFilename [protected] |
Definition at line 56 of file CryptLibraryDemoDlg.h.
CEdit CCryptLibraryDemoDlg::m_editInputName [protected] |
Definition at line 58 of file CryptLibraryDemoDlg.h.
CEdit CCryptLibraryDemoDlg::m_editOutputName [protected] |
Definition at line 59 of file CryptLibraryDemoDlg.h.
HICON CCryptLibraryDemoDlg::m_hIcon [protected] |
Definition at line 52 of file CryptLibraryDemoDlg.h.
CString CCryptLibraryDemoDlg::m_strChecksum [protected] |
Definition at line 61 of file CryptLibraryDemoDlg.h.
CString CCryptLibraryDemoDlg::m_strFilename [protected] |
Definition at line 60 of file CryptLibraryDemoDlg.h.
CString CCryptLibraryDemoDlg::m_strInputName [protected] |
Definition at line 62 of file CryptLibraryDemoDlg.h.
CString CCryptLibraryDemoDlg::m_strOutputName [protected] |
Definition at line 63 of file CryptLibraryDemoDlg.h.
1.7.3