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

📄 des1dlg.cpp

📁 该程序能实现将数字签名嵌入到BMP图片中形成数字印章
💻 CPP
字号:
// DES1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "PKI.h"
#include "PKIDlg.h"
#include "DES1Dlg.h"
#include "DES.h"
//#include "Main1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDES1Dlg dialog


CDES1Dlg::CDES1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDES1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDES1Dlg)
	m_filename = _T("");
	m_filekey = _T("");
	m_savefile = _T("");
	m_savefile1 = _T("");
	m_plain = _T("");
	m_key = _T("");
	m_enc = _T("");
	m_back = _T("");
	//}}AFX_DATA_INIT
}


void CDES1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDES1Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_filename);
	DDX_Text(pDX, IDC_EDIT2, m_filekey);
	DDX_Text(pDX, IDC_EDIT3, m_savefile);
	DDX_Text(pDX, IDC_EDIT4, m_savefile1);
	DDX_Text(pDX, IDC_EDIT5, m_plain);
	DDX_Text(pDX, IDC_EDIT6, m_key);
	DDX_Text(pDX, IDC_EDIT7, m_enc);
	DDX_Text(pDX, IDC_EDIT8, m_back);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDES1Dlg, CDialog)
	//{{AFX_MSG_MAP(CDES1Dlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnENC)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON7, OnENCDATA)
	ON_BN_CLICKED(IDC_BUTTON8, OnDEC)
	ON_BN_CLICKED(IDC_BUTTON9, Onclear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDES1Dlg message handlers

void CDES1Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CFileDialog dlg(1,NULL,NULL,OFN_HIDEREADONLY ,"All Files(*.*)|*.*||");
	if(IDOK!=dlg.DoModal())return;
	m_filename=dlg.GetPathName();	
	UpdateData(FALSE);	
}

void CDES1Dlg::OnENC() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
    if(m_filename=="")return;
    CFile ff(m_filename,CFile::modeRead);
    long lFileLen=ff.GetLength();
    long c=lFileLen/8;
    long d=lFileLen%8;
    if (m_savefile=="")
    m_savefile=m_filename+".aen";


    CFile fp(m_savefile,CFile::modeCreate|CFile::modeWrite);
    fp.SeekToBegin();
    ff.SeekToBegin();

//CString inbuff;


    DES jm;




    char inbuff[8],oubuff[8],skey[8];

/*	char *cr=NULL;
for(int j=0;j<16;j++)
 {
CString str=m_filekey.Mid(2*j,2);
skey[j]=unsigned char(strtol(str,&cr,16));
}*/
    memcpy(skey,(LPCTSTR)m_filekey,8);

	for(long i=0;i<c;i++)
	{
		ff.Read(inbuff,8);
		jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
		fp.Write(oubuff,8);
	}
	if(d)
	{   memset(inbuff,0,8);
		ff.Read(inbuff,d);
		jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
		fp.Write(oubuff,8);
	}
     
	ff.Close();
	fp.Close();
	AfxMessageBox("加密成功!");
	UpdateData(FALSE);
}

void CDES1Dlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	 UpdateData(TRUE);
   if(m_savefile=="")return;
   CFile ff(m_savefile,CFile::modeRead);
   long lFileLen=ff.GetLength();
   long c=lFileLen/8;
   long d=lFileLen%8;
   if (m_savefile1=="")
   m_savefile1=m_savefile+".aen";
   CFile fp(m_savefile1,CFile::modeCreate|CFile::modeWrite);
   fp.SeekToBegin();
   ff.SeekToBegin();

//CString inbuff;


DES jm;

 char inbuff[8],oubuff[8],skey[8];

 memcpy(skey,(LPCTSTR)m_filekey,8);


for(long i=0;i<c;i++)
	{
		ff.Read(inbuff,8);
		
        jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), DECRYPT);
		fp.Write(oubuff,8);
	}
	if(d)
	{
        memset(inbuff,0,8);
		ff.Read(inbuff,d);
		jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
		fp.Write(oubuff,8);
	}
    
	ff.Close();
	fp.Close();
	AfxMessageBox("解密成功!");
	UpdateData(FALSE);		
}

void CDES1Dlg::OnButton4() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_filename="";
	m_filekey="";
	m_savefile="";
	m_savefile1="";
	UpdateData(FALSE);
}

void CDES1Dlg::OnButton5() 
{
	// TODO: Add your control notification handler code here
	CPKIDlg dlg;
	dlg.DoModal();
	CDialog::OnCancel();
}

void CDES1Dlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

void CDES1Dlg::OnENCDATA() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	char skey[32];
    char inbuff[32],oubuff[32];
	memcpy(skey,(LPCTSTR)m_key,8);
	int k=sizeof(inbuff);
	memcpy(inbuff,(LPCTSTR)m_plain,k);
    CString strTmp,str;
    DES jm	;
    jm.Des_Go(oubuff, inbuff, sizeof(inbuff), skey,sizeof(skey), ENCRYPT);
    for(int i=0;i<k;i++)
    str+=oubuff[i];     
    m_enc=str;
    UpdateData(FALSE);
}

void CDES1Dlg::OnDEC() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
    char skey[32];
    char inbuff[32],oubuff[32];
	memcpy(skey,(LPCTSTR)m_key,8);
	int c=sizeof(inbuff);
	memcpy(inbuff,(LPCTSTR)m_enc,c);
    CString strTmp,str;
    DES jm	;
    jm.Des_Go(oubuff, inbuff, sizeof(inbuff),skey, sizeof(skey),  DECRYPT);
    int k=sizeof(oubuff);
    for(int i=0;i<k;i++)
    str +=oubuff[i];
    m_back=str;
    UpdateData(FALSE);	
}

void CDES1Dlg::Onclear() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_plain="";
	m_key="";
	m_enc="";
	m_back="";
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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