📄 filecryptdlg.cpp
字号:
m_oToolTipCtrl.AddTool(&m_oEditKeyDataHex, IDS_EDITKEYDATAHEX);
m_oToolTipCtrl.AddTool(&m_oComboOpMode, IDS_COMBOOPMODE);
m_oToolTipCtrl.AddTool(&m_oComboPadding, IDS_COMBOPADDING);
m_oToolTipCtrl.AddTool(&m_oEditExtRounds, IDS_EDITEXTROUNDS);
m_oToolTipCtrl.AddTool(&m_oEditIntRounds, IDS_EDITINTROUNDS);
m_oToolTipCtrl.AddTool(&m_oBtnAction, IDS_BTNACTION);
m_oToolTipCtrl.AddTool(&m_oEdtStr, IDS_EDTSTR);
m_oToolTipCtrl.AddTool(&m_oEdtStrHex, IDS_EDTSTRHEX);
m_oToolTipCtrl.AddTool(&m_oEdtEnc, IDS_EDTENC);
m_oToolTipCtrl.AddTool(&m_oEdtEncHex, IDS_EDTHEX);
//
m_oToolTipCtrl.AddTool(&m_oEdtDir1, IDS_EDTDIR1);
m_oToolTipCtrl.AddTool(&m_oBtnDir1, IDS_BTNDIR1);
m_oToolTipCtrl.AddTool(&m_oEdtExt1, IDS_EDTEXT1);
m_oToolTipCtrl.AddTool(&m_oEdtFile1, IDS_EDTFILE1);
m_oToolTipCtrl.AddTool(&m_oBtnFile1, IDS_BTNFILE1);
//
m_oToolTipCtrl.AddTool(&m_oEdtDir3, IDS_EDTDIR3);
m_oToolTipCtrl.AddTool(&m_oBtnDir3, IDS_BTNDIR3);
m_oToolTipCtrl.AddTool(&m_oEdtExt3, IDS_EDTEXT3);
m_oToolTipCtrl.AddTool(&m_oEdtFile3, IDS_EDTFILE3);
m_oToolTipCtrl.AddTool(&m_oBtnFile3, IDS_BTNFILE3);
//
m_oToolTipCtrl.Activate(TRUE);
}
//Moving the Controls
MoveStringGroup();
MoveFileGroup();
//
CRect oRect, oRectDlg;
CWnd* poWnd = GetDlgItem(IDC_STATIC3);
poWnd->GetWindowRect(&oRect);
GetWindowRect(&oRectDlg);
SetWindowPos(NULL, 0, 0, oRectDlg.Width(), oRect.bottom-oRectDlg.top+15, SWP_NOMOVE|SWP_NOZORDER);
//
CButton* poButton;
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADENCRYPT));
poButton->SetCheck(1);
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADFILE));
poButton->SetCheck(1);
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADKEY));
poButton->SetCheck(1);
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADPLAIN));
poButton->SetCheck(1);
//Spin Buttons
UDACCEL oACCEL;
oACCEL.nInc = 1;
oACCEL.nSec = 1;
//Block Size
CSpinButtonCtrl* poSpinBlockSize = static_cast<CSpinButtonCtrl*>(GetDlgItem(IDC_SPINBLOCKSIZE));
CEdit* poEditBlockSize = static_cast<CEdit*>(GetDlgItem(IDC_EDITBLOCKSIZE));
poSpinBlockSize->SetBuddy(poEditBlockSize);
poSpinBlockSize->SetRange(4, 256);
poSpinBlockSize->SetPos(16);
poSpinBlockSize->SetAccel(1, &oACCEL);
//External Rounds
CSpinButtonCtrl* poSpinExtRounds = static_cast<CSpinButtonCtrl*>(GetDlgItem(IDC_SPINEXTROUNDS));
CEdit* poEditExtRounds = static_cast<CEdit*>(GetDlgItem(IDC_EDITEXTROUNDS));
poSpinExtRounds->SetBuddy(poEditExtRounds);
poSpinExtRounds->SetRange(3, 100); //UD_MAXVAL);
poSpinExtRounds->SetPos(4);
poSpinExtRounds->SetAccel(1, &oACCEL);
//Internal Rounds
CSpinButtonCtrl* poSpinIntRounds = static_cast<CSpinButtonCtrl*>(GetDlgItem(IDC_SPININTROUNDS));
CEdit* poEditIntRounds = static_cast<CEdit*>(GetDlgItem(IDC_EDITINTROUNDS));
poSpinIntRounds->SetBuddy(poEditIntRounds);
poSpinIntRounds->SetRange(3, 100);
poSpinIntRounds->SetPos(4);
poSpinIntRounds->SetAccel(1, &oACCEL);
//Initialize Combo Boxes
CComboBox* poComboBox;
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOMETHODS));
poComboBox->SetCurSel(0);
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOKEYSIZE));
poComboBox->SetCurSel(0);
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOBLOCKSIZE));
poComboBox->SetCurSel(0);
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOOPMODE));
poComboBox->SetCurSel(0);
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOPADDING));
poComboBox->SetCurSel(0);
//Initialize the Transparent Bitmaps
m_oBMP1.LoadBitmap(IDB_ARROWDOWN);
m_oBMP2.LoadBitmap(IDB_ARROWUP);
m_oTransparentBitmap1.SubclassDlgItem(IDC_STATICBMP1, this);
m_oTransparentBitmap1.Initialize(HBITMAP(m_oBMP1), RGB(255,255,255), 1.0, 1.0);
m_oTransparentBitmap2.SubclassDlgItem(IDC_STATICBMP2, this);
m_oTransparentBitmap2.Initialize(HBITMAP(m_oBMP1), RGB(255,255,255), 1.0, 1.0);
CEdit* poEdit;
poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDTEXT1));
poEdit->SetWindowText(_T("*"));
poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDTEXT3));
poEdit->SetWindowText(_T("*"));
TCHAR szCurDir[MAX_PATH+1];
::GetCurrentDirectory(MAX_PATH, szCurDir);
poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDTDIR1));
poEdit->SetWindowText(CString(szCurDir));
poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDTDIR3));
poEdit->SetWindowText(CString(szCurDir));
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileCryptDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFileCryptDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFileCryptDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFileCryptDlg::OnRadencrypt()
{
m_iAction = ENCRYPT;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_BTNACTION));
poButton->SetWindowText(_T("&Encrypt"));
m_oTransparentBitmap1.ChangeBitmap(HBITMAP(m_oBMP1));
m_oTransparentBitmap2.ChangeBitmap(HBITMAP(m_oBMP1));
}
void CFileCryptDlg::OnRaddecrypt()
{
m_iAction = DECRYPT;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_BTNACTION));
poButton->SetWindowText(_T("&Decrypt"));
m_oTransparentBitmap1.ChangeBitmap(HBITMAP(m_oBMP2));
m_oTransparentBitmap2.ChangeBitmap(HBITMAP(m_oBMP2));
}
void GetFirstString(CString& roStr)
{
roStr.TrimLeft();
roStr.TrimRight();
if(roStr != _T(""))
{
int iPos;
//Find the first blank position
if((iPos=roStr.Find(_T(' '))) != -1)
roStr = roStr.Left(iPos);
}
}
void CFileCryptDlg::OnBtnaction()
{
if(FILE == m_iMode)
ActionFile();
else
ActionString();
}
void CFileCryptDlg::AESParams(CString& roStrKeyData, BOOL& rbHex, int& riKeyLength, int& riBlockSize, int& riMode, int& riPadding)
{
CString oStr;
CWnd* poWnd;
rbHex = FALSE;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_RADKEYHEX));
if(1 == poButton->GetCheck())
{
poWnd = GetDlgItem(IDC_EDITKEYDATAHEX);
rbHex = TRUE;
}
else
poWnd = GetDlgItem(IDC_EDITKEYDATA);
poWnd->GetWindowText(roStrKeyData);
//Key Length
poWnd = GetDlgItem(IDC_COMBOKEYSIZE);
poWnd->GetWindowText(oStr);
riKeyLength = atoi(LPCTSTR(oStr));
//Block Size
poWnd = GetDlgItem(IDC_COMBOBLOCKSIZE);
poWnd->GetWindowText(oStr);
riBlockSize = atoi(LPCTSTR(oStr));
//Mode
poWnd = GetDlgItem(IDC_COMBOOPMODE);
poWnd->GetWindowText(oStr);
if(_T("ECB") == oStr)
riMode = IMethod::ECB;
else if(_T("CBC") == oStr)
riMode = IMethod::CBC;
else if(_T("CFB") == oStr)
riMode = IMethod::CFB;
else
ASSERT(FALSE);
//Padding
poWnd = GetDlgItem(IDC_COMBOPADDING);
poWnd->GetWindowText(oStr);
if(_T("ZEROES") == oStr)
riPadding = IMethod::ZEROES;
else if(_T("BLANKS") == oStr)
riPadding = IMethod::BLANKS;
else if(_T("PKCS7") == oStr)
riPadding = IMethod::PKCS7;
else
ASSERT(FALSE);
}
void CFileCryptDlg::BlowFishParams(CString& roStrKeyData, BOOL& rbHex, int& riMode, int& riPadding)
{
CString oStr;
CWnd* poWnd;
rbHex = FALSE;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_RADKEYHEX));
if(1 == poButton->GetCheck())
{
poWnd = GetDlgItem(IDC_EDITKEYDATAHEX);
rbHex = TRUE;
}
else
poWnd = GetDlgItem(IDC_EDITKEYDATA);
poWnd->GetWindowText(roStrKeyData);
//Mode
poWnd = GetDlgItem(IDC_COMBOOPMODE);
poWnd->GetWindowText(oStr);
if(_T("ECB") == oStr)
riMode = IMethod::ECB;
else if(_T("CBC") == oStr)
riMode = IMethod::CBC;
else if(_T("CFB") == oStr)
riMode = IMethod::CFB;
else
ASSERT(FALSE);
//Padding
poWnd = GetDlgItem(IDC_COMBOPADDING);
poWnd->GetWindowText(oStr);
if(_T("ZEROES") == oStr)
riPadding = IMethod::ZEROES;
else if(_T("BLANKS") == oStr)
riPadding = IMethod::BLANKS;
else if(_T("PKCS7") == oStr)
riPadding = IMethod::PKCS7;
else
ASSERT(FALSE);
}
void CFileCryptDlg::TEAParams(CString& roStrKeyData, BOOL& rbHex, int& riMode, int& riPadding)
{
CString oStr;
CWnd* poWnd;
rbHex = FALSE;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_RADKEYHEX));
if(1 == poButton->GetCheck())
{
poWnd = GetDlgItem(IDC_EDITKEYDATAHEX);
rbHex = TRUE;
}
else
poWnd = GetDlgItem(IDC_EDITKEYDATA);
poWnd->GetWindowText(roStrKeyData);
//Mode
poWnd = GetDlgItem(IDC_COMBOOPMODE);
poWnd->GetWindowText(oStr);
if(_T("ECB") == oStr)
riMode = IMethod::ECB;
else if(_T("CBC") == oStr)
riMode = IMethod::CBC;
else if(_T("CFB") == oStr)
riMode = IMethod::CFB;
else
ASSERT(FALSE);
//Padding
poWnd = GetDlgItem(IDC_COMBOPADDING);
poWnd->GetWindowText(oStr);
if(_T("ZEROES") == oStr)
riPadding = IMethod::ZEROES;
else if(_T("BLANKS") == oStr)
riPadding = IMethod::BLANKS;
else if(_T("PKCS7") == oStr)
riPadding = IMethod::PKCS7;
else
ASSERT(FALSE);
}
void CFileCryptDlg::XOR256BlockParams(CString& roStrKeyData, BOOL& rbHex, int& riBlockSize, int& riORounds,
int& riIRounds, int& riMode, int& riPadding)
{
CString oStr;
CWnd* poWnd;
rbHex = FALSE;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_RADKEYHEX));
if(1 == poButton->GetCheck())
{
poWnd = GetDlgItem(IDC_EDITKEYDATAHEX);
rbHex = TRUE;
}
else
poWnd = GetDlgItem(IDC_EDITKEYDATA);
poWnd->GetWindowText(roStrKeyData);
//Block Size
poWnd = GetDlgItem(IDC_EDITBLOCKSIZE);
poWnd->GetWindowText(oStr);
riBlockSize = atoi(LPCTSTR(oStr));
//External Rounds
poWnd = GetDlgItem(IDC_EDITEXTROUNDS);
poWnd->GetWindowText(oStr);
riORounds = atoi(LPCTSTR(oStr));
//Internal Rounds
poWnd = GetDlgItem(IDC_EDITINTROUNDS);
poWnd->GetWindowText(oStr);
riIRounds = atoi(LPCTSTR(oStr));
//Mode
poWnd = GetDlgItem(IDC_COMBOOPMODE);
poWnd->GetWindowText(oStr);
if(_T("ECB") == oStr)
riMode = IMethod::ECB;
else if(_T("CBC") == oStr)
riMode = IMethod::CBC;
else if(_T("CFB") == oStr)
riMode = IMethod::CFB;
else
ASSERT(FALSE);
//Padding
poWnd = GetDlgItem(IDC_COMBOPADDING);
poWnd->GetWindowText(oStr);
if(_T("ZEROES") == oStr)
riPadding = IMethod::ZEROES;
else if(_T("BLANKS") == oStr)
riPadding = IMethod::BLANKS;
else if(_T("PKCS7") == oStr)
riPadding = IMethod::PKCS7;
else
ASSERT(FALSE);
}
void CFileCryptDlg::XOR256StreamParams(CString& roStrKeyData, BOOL& rbHex, int& riIRounds)
{
CString oStr;
CWnd* poWnd;
rbHex = FALSE;
CButton* poButton = static_cast<CButton*>(GetDlgItem(IDC_RADKEYHEX));
if(1 == poButton->GetCheck())
{
poWnd = GetDlgItem(IDC_EDITKEYDATAHEX);
rbHex = TRUE;
}
else
poWnd = GetDlgItem(IDC_EDITKEYDATA);
poWnd->GetWindowText(roStrKeyData);
//Internal Rounds
poWnd = GetDlgItem(IDC_EDITINTROUNDS);
poWnd->GetWindowText(oStr);
riIRounds = atoi(LPCTSTR(oStr));
}
IMethod* CFileCryptDlg::GetMethod(int iMethod)
{
IMethod* poMethod;
CString oStrKeyData;
BOOL bHex;
int iLength;
switch(iMethod)
{
case AES:
{
int iMode, iPadding;
int iKeyLength, iBlockSize;
AESParams(oStrKeyData, bHex, iKeyLength, iBlockSize, iMode, iPadding);
if(NULL == m_apAES.get())
//Create First Time
m_apAES = auto_ptr<CRijndael>(new CRijndael());
char acKey[32];
iLength = oStrKeyData.GetLength();
if(TRUE == bHex)
{
iLength /= 2;
if(iLength > 32)
iLength = 32;
Hex2Binary(LPCTSTR(oStrKeyData), reinterpret_cast<unsigned char*>(acKey), iLength);
}
else
strncpy(acKey, LPCTSTR(oStrKeyData), 32);
m_apAES->Initialize(acKey, 32, CRijndael::sm_chain0, iKeyLength, iBlockSize,
iMode, iPadding);
poMethod = m_apAES.get();
break;
}
case BLOWFISH:
{
int iMode, iPadding;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -