⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 文件保险箱dlg.cpp

📁 安全文件柜,使用CryptApi接口实现.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 文件保险箱Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "文件保险箱.h"
#include "文件保险箱Dlg.h"
#include "GetPassDlg.h"
#include <stdio.h>
#include <windows.h>
#include "eboy_wincrypt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
ALG_LIST g_Alg_List[]=
{
	{"RC2算法",CALG_RC2},
	{"DES算法",CALG_DES},
	{"3DES算法",CALG_3DES},
	{NULL,0}
};


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_COMBO1, m_ALGLIST);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::OnInitDialog()
{
	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)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		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
	
	// TODO: Add extra initialization here
	m_ALGLIST.Clear();
	for(int i=0;;i++)//添加支持的算法到列表框
	{
		if(g_Alg_List[i].nAlgID ==0)
		{
			break;
		}
		m_ALGLIST.InsertString(i,g_Alg_List[i].strAlgName);
	}
	m_ALGLIST.SetCurSel(i-1);
	
 
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//设置待加密的原文文件路径
void CMyDlg::OnButton1() 
{
	static char BASED_CODE szFilter[] = "全部文件 (*.*)|*.*||";
	
	CFileDialog filedlg(
		TRUE,NULL,NULL,
		OFN_EXPLORER,
		szFilter);
	
	if(filedlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_EDIT1,filedlg.GetPathName());		
	}
	
}
//设置加密后的密文文件路径
void CMyDlg::OnButton2() 
{
	static char BASED_CODE szFilter[] = "全部文件 (*.*)|*.*||";
	
	CFileDialog filedlg(
		TRUE,NULL,NULL,
		OFN_EXPLORER,
		szFilter);
	
	if(filedlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_EDIT2,filedlg.GetPathName());		
	}
}
//设置待解密的密文文件路径
void CMyDlg::OnButton4() 
{
	static char BASED_CODE szFilter[] = "全部文件 (*.*)|*.*||";
	
	CFileDialog filedlg(
		TRUE,NULL,NULL,
		OFN_EXPLORER,
		szFilter);
	
	if(filedlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_EDIT3,filedlg.GetPathName());		
	}
}
//设置解密后的原文文件路径
void CMyDlg::OnButton5() 
{
	static char BASED_CODE szFilter[] = "全部文件 (*.*)|*.*||";
	
	CFileDialog filedlg(
		TRUE,NULL,NULL,
		OFN_EXPLORER,
		szFilter);
	
	if(filedlg.DoModal()==IDOK)
	{
		SetDlgItemText(IDC_EDIT4,filedlg.GetPathName());		
	}
}
//文件加密
void CMyDlg::OnButton3() 
{
	CString strPlainFilePath;
	CString strCipherFilePath;
	DWORD nAlg_ID;
	CString strPass;
	GetPassDlg passdDlg;
	//获得原文和密文文件的路径
	GetDlgItemText(IDC_EDIT1,strPlainFilePath);	
	GetDlgItemText(IDC_EDIT2,strCipherFilePath);
	if(strCipherFilePath.IsEmpty()||strPlainFilePath.IsEmpty())
	{
		AfxMessageBox("请输入正确的文件路径!");
		return;
	}
	if(strCipherFilePath==strPlainFilePath)
	{
		AfxMessageBox("密文文件和原文文件不能为同一个文件!");
		return;

	}
	//获得密码算法
	nAlg_ID = g_Alg_List[m_ALGLIST.GetCurSel()].nAlgID;
#ifdef _DEBUG
	AfxMessageBox(strPlainFilePath);
	AfxMessageBox(strCipherFilePath);
	AfxMessageBox(g_Alg_List[m_ALGLIST.GetCurSel()].strAlgName);
#endif
	//获得文件保护密码
	if(passdDlg.DoModal()==IDOK)
	{
		strPass = passdDlg.m_Pass;
	}
	else
	{
		AfxMessageBox("请输入加密文件的密码");
		return;
	}
#ifdef _DEBUG
	AfxMessageBox(strPass);
#endif
	 if(Encrypt_File(strPlainFilePath,strCipherFilePath,nAlg_ID,strPass))
	 {
		 AfxMessageBox("加密文件成功");
	 }
	 else
	 {
		AfxMessageBox("加密文件失败");
	 }
	
}
//文件解密
void CMyDlg::OnButton6() 
{
	CString strPlainFilePath;
	CString strCipherFilePath;
	CString strPass;
	GetPassDlg passdDlg;
	//获得原文和密文文件的路径
	GetDlgItemText(IDC_EDIT4,strPlainFilePath);	
	GetDlgItemText(IDC_EDIT3,strCipherFilePath);
	if(strCipherFilePath.IsEmpty()||strPlainFilePath.IsEmpty())
	{
		AfxMessageBox("请输入正确的文件路径!");
		return;
	}
	if(strCipherFilePath==strPlainFilePath)
	{
		AfxMessageBox("密文文件和原文文件不能为同一个文件!");
		return;
		
	}
	
#ifdef _DEBUG
	AfxMessageBox(strPlainFilePath);
	AfxMessageBox(strCipherFilePath);
#endif
	//获得文件保护密码
	if(passdDlg.DoModal()==IDOK)
	{
		strPass = passdDlg.m_Pass;
	}
	else
	{
		AfxMessageBox("请输入加密文件的密码");
		return;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -