• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 15KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2010-04-13 09:27
    上传日期
对文件进行加密、解密,保证在不知道密码的情况下不能打开加密文件,保证文件内容的安全性。
FileEncry.rar
  • res
  • FileEncry.rc2
    401B
  • FileEncry.ico
    1.1KB
  • resource.h
    917B
  • FileEncry.cpp
    2.1KB
  • FileEncryDlg.cpp
    6.6KB
  • FileEncryDlg.h
    1.4KB
  • FileEncry.clw
    1.2KB
  • FileEncry.ncb
    57KB
  • FileEncry.h
    1.3KB
  • FileEncry.dsp
    4.1KB
  • StdAfx.cpp
    211B
  • FileEncry.dsw
    543B
  • FileEncry.rc
    5.4KB
  • StdAfx.h
    1KB
  • FileEncry.plg
    2.1KB
内容介绍
// FileEncryDlg.cpp : implementation file // #include "stdafx.h" #include "FileEncry.h" #include "FileEncryDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // 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() ///////////////////////////////////////////////////////////////////////////// // CFileEncryDlg dialog CFileEncryDlg::CFileEncryDlg(CWnd* pParent /*=NULL*/) : CDialog(CFileEncryDlg::IDD, pParent) { //{{AFX_DATA_INIT(CFileEncryDlg) // 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 CFileEncryDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFileEncryDlg) DDX_Control(pDX, IDC_FILEPATH, m_filepath); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFileEncryDlg, CDialog) //{{AFX_MSG_MAP(CFileEncryDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BTOPEN, OnOpen) ON_BN_CLICKED(IDC_BTENCRY, OnEncry) ON_BN_CLICKED(IDC_BTUNENCRY, OnUnEncry) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFileEncryDlg message handlers BOOL CFileEncryDlg::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 return TRUE; // return TRUE unless you set the focus to a control } void CFileEncryDlg::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 CFileEncryDlg::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 CFileEncryDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CFileEncryDlg::OnOpen() { CFileDialog log(TRUE,"文件",NULL,OFN_HIDEREADONLY,"FILE(*.txt)|*.txt||",NULL); if(log.DoModal()==IDOK) { CString tmp,str,path; path=log.GetPathName(); strpathtemp=log.GetFileName(); int pos=path.Find(strpathtemp); strpathtemp=path.Left(pos); CStdioFile file; try{ int i=file.Open(path,CFile::modeRead); if(i==0) return; }catch(CFileException *e) { TCHAR szBuf[256]; e->GetErrorMessage(szBuf,256,NULL); MessageBox(szBuf,_T("Warning")); e->Delete(); } while(1) { DWORD i=file.ReadString(str); if(i==0)goto end; tmp+=str; tmp+="\r\n"; } end: GetDlgItem(IDC_EDBODY)->SetWindowText(tmp); m_filepath.SetWindowText(path); } } void CFileEncryDlg::OnEncry() { CString path,desname; m_filepath.GetWindowText(path); if(path.IsEmpty())return; desname.Format("%smingrisofttemp.txt",strpathtemp); HANDLE handle=::CreateFile(desname,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL); if(handle)::CloseHandle(handle); CFile readfile,writefile; int i=readfile.Open(path,CFile::modeRead); writefile.Open(desname,CFile::modeCreate|CFile::modeReadWrite); if(i==0)return; char buf[128]; char desbuf[128]; while(1) { ZeroMemory(buf,128); ZeroMemory(desbuf,128); DWORD i=readfile.Read(buf,128); for(int p=0;p<i;p++) { char m=buf[p]; desbuf[p]=m^2; } writefile.Write(desbuf,i); if(i==0)goto end; } end: readfile.Close(); writefile.Close(); ::DeleteFile(path); ::rename(desname,path); AfxMessageBox("加密完成"); } void CFileEncryDlg::OnUnEncry() { CString path,desname; m_filepath.GetWindowText(path); if(path.IsEmpty())return; desname.Format("%smingrisofttemp.txt",strpathtemp); HANDLE handle=::CreateFile(desname,GENERIC_WRITE,FILE_SHARE_WRITE,0,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL); if(handle)::CloseHandle(handle); CFile readfile,writefile; int i=readfile.Open(path,CFile::modeRead); writefile.Open(desname,CFile::modeCreate|CFile::modeReadWrite); if(i==0)return; char buf[128]; char desbuf[128]; while(1) { ZeroMemory(buf,128); ZeroMemory(desbuf,128); DWORD i=readfile.Read(buf,128); for(int p=0;p<i;p++) { char m=buf[p]; desbuf[p]=m^2; } writefile.Write(desbuf,i); if(i==0)goto end; } end: readfile.Close(); writefile.Close(); ::DeleteFile(path); ::rename(desname,path); AfxMessageBox("解密完成"); }
评论
    相关推荐
    • 3DES加密算法源代码.rar
      DES加密源代码,用3DES加密算法。 加密强度高,到目前为止,还无人能够破解!
    • crc.zip
      CRC校验程序,使用了CRC-16和CRC-CCITT方法
    • rsa1.03.zip
      rsa算法实现,包含文档
    • fast-des3.0.tar.z
      des算法实现源码
    • des3_win32_vc.zip
      一个3des算法的库文件和使用库文件的例子
    • dcpcrypt.zip
      Delphi加密控件源码,包括对称钥匙加密控件和散列函数控件
    • rc.zip
      含有rc2、rc4、rc5、rc6算法的rc算法集合
    • oicqpass.zip
      读取OICQ用户保存在本地机器上的密码
    • elgamal.zip
      另一种公开密钥加密算法的Pascal实现和例子。实现了签名和确认
    • linuxscanners.zip
      linux下的端口扫描器