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

📄 usbcertpage.cpp

📁 MiniCA减肥修正版 大部分源码来自王雪松的原作以及OpenSSL。(文件名基本保持原样
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		{
			m_List.AddMsg("修改P12密码成功");
		}
		else
		{
			out=(char *)Get_Func_Err(0);
			m_List.AddMsg(out,M_ERROR);
		}
	}
	else	//修改私钥文件密码
	{
		CString pwd,pwd2,pwd3,filein,fileOut;
		GetDlgItemText(IDC_EDIT_KEY,filein);
		if(filein=="")
		{
			m_List.AddMsg("请选择私钥文件!",M_WARING);
			return;
		}
		GetDlgItemText(IDC_EDIT_PASSWORD,pwd);
		GetDlgItemText(IDC_EDIT_PASSWORD2,pwd2);
		GetDlgItemText(IDC_EDIT_PASSWORD3,pwd3);
		if(pwd2!=pwd3)
		{
			m_List.AddMsg("新设密码和重复密码不一致!",M_WARING);
			return;
		}
		
		char *out,chipme[16]={0};
		//读取所选的加密算法名称
		int crIndex=SendDlgItemMessage(IDC_COMBO_CRYPT1,CB_GETCURSEL,0,0);
		SendDlgItemMessage(IDC_COMBO_CRYPT1,CB_GETLBTEXT,crIndex,(long)&chipme);
		fileOut=m_Path+".prk";
//	int ChangePrkPW(char *fileIn,char *OldPwd,char *NewPwd,char *cipher,char *fileOut);
		if(ChangePrkPW(filein.GetBuffer(0),pwd.GetBuffer(0),pwd2.GetBuffer(0),chipme,fileOut.GetBuffer(0)))
		{
			m_List.AddMsg("修改私钥密码成功");
		}
		else
		{
			out=(char *)Get_Func_Err(0);
			m_List.AddMsg(out,M_ERROR);
		}
	}
}

void CUsbCertPage::SetCheck()
{
	SetDlgItemText(IDC_EDIT_P12,"");
	SetDlgItemText(IDC_EDIT_KEY,"");
	SetDlgItemText(IDC_EDIT_PASSWORD,"");
	SetDlgItemText(IDC_EDIT_PASSWORD2,"");
	SetDlgItemText(IDC_EDIT_PASSWORD3,"");
	
	if(m_Type==0)
	{
		
		GetDlgItem(IDC_EDIT_P12)->EnableWindow(1);
		SetDlgItemText(IDC_B_PUB,"选择P12");
		GetDlgItem(IDC_B_PUB)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD2)->EnableWindow(0);	
		GetDlgItem(IDC_EDIT_PASSWORD3)->EnableWindow(0);	
		
		GetDlgItem(IDC_EDIT_KEY)->EnableWindow(0);
		GetDlgItem(IDC_B_KEY)->EnableWindow(0);	
		GetDlgItem(IDC_COMBO_CRYPT1)->EnableWindow(0);

	}
	else if(m_Type==1)
	{
		GetDlgItem(IDC_EDIT_P12)->EnableWindow(1);
		SetDlgItemText(IDC_B_PUB,"选择公钥");
		GetDlgItem(IDC_B_PUB)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(0);	
		
		GetDlgItem(IDC_EDIT_KEY)->EnableWindow(1);
		GetDlgItem(IDC_B_KEY)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD2)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD3)->EnableWindow(1);	
		GetDlgItem(IDC_COMBO_CRYPT1)->EnableWindow(0);

	}
	else if(m_Type==2)
	{
		GetDlgItem(IDC_EDIT_P12)->EnableWindow(1);
		SetDlgItemText(IDC_B_PUB,"选择P12");
		GetDlgItem(IDC_B_PUB)->EnableWindow(1);	
		GetDlgItem(IDC_COMBO_CRYPT1)->EnableWindow(0);
		GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(1);	
		
		GetDlgItem(IDC_EDIT_KEY)->EnableWindow(0);
		GetDlgItem(IDC_B_KEY)->EnableWindow(0);	
		GetDlgItem(IDC_EDIT_PASSWORD2)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD3)->EnableWindow(1);	
		
	}
	else
	{
		GetDlgItem(IDC_EDIT_P12)->EnableWindow(0);
		GetDlgItem(IDC_B_PUB)->EnableWindow(0);	
		GetDlgItem(IDC_COMBO_CRYPT1)->EnableWindow(1);
		GetDlgItem(IDC_EDIT_KEY)->EnableWindow(1);
		GetDlgItem(IDC_B_KEY)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD2)->EnableWindow(1);	
		GetDlgItem(IDC_EDIT_PASSWORD3)->EnableWindow(1);	
	}

}

void CUsbCertPage::SetCheck1()
{
	if(n_Type==3)
	{
		SetDlgItemText(IDC_BSOUT,"公钥文件");
		SetDlgItemText(IDC_BSIN,"私钥文件");
	}
	else
	{
		SetDlgItemText(IDC_BSOUT,"输入文件");
		SetDlgItemText(IDC_BSIN,"输出文件");
	}
}

void CUsbCertPage::OnRParse() //提取证书操作
{
	// TODO: Add your control notification handler code here
	m_Type=0;
	SetCheck();
	
}

void CUsbCertPage::OnRCreate() //合并证书操作
{
	// TODO: Add your control notification handler code here
	m_Type=1;
	SetCheck();
	
}

void CUsbCertPage::OnRChangep() //修改密码操作
{
	// TODO: Add your control notification handler code here
	m_Type=2;
	SetCheck();
}

void CUsbCertPage::OnRChangep2() 
{
	// TODO: Add your control notification handler code here
	m_Type=3;
	SetCheck();
}

void CUsbCertPage::OnTODER()
{
	// TODO: Add your control notification handler code here
	n_Type=0;
	SetCheck1();
}

void CUsbCertPage::OnTOPEM()
{
	// TODO: Add your control notification handler code here
	n_Type=1;
	SetCheck1();
}

void CUsbCertPage::OnTOPVK()
{
	// TODO: Add your control notification handler code here
	n_Type=2;
	SetCheck1();
}

void CUsbCertPage::OnVERIFY()
{
	// TODO: Add your control notification handler code here
	n_Type=3;
	SetCheck1();
}

void CUsbCertPage::OnBsout() //选择输入文件
{
	// TODO: Add your control notification handler code here
	CFileDialog dlgOpen(true,NULL,NULL,OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
		"证书文件(*.crt,*.cer,*.pem,*.der,*.pvk,*.prk)|*.crt;*.cer;*.pem;*.der;*.pvk;*.prk||",NULL);
	dlgOpen.m_ofn.lpstrTitle="选择证书文件";//标题条
	if(dlgOpen.DoModal()!=IDOK) return;
	SetDlgItemText(IDC_EDIT_INFILE,dlgOpen.GetPathName());
}

void CUsbCertPage::OnBsin() //选择输出文件
{
	// TODO: Add your control notification handler code here
	CFileDialog dlgOpen(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"证书文件(*.crt,*.cer,*.pem,*.der,*.pvk,*.prk)|*.crt;*.cer;*.pem;*.der;*.pvk;*.prk||",NULL);
	dlgOpen.m_ofn.lpstrTitle="保存证书文件";//标题条
	if(dlgOpen.DoModal()!=IDOK) return;
	SetDlgItemText(IDC_EDIT_OUTFILE,dlgOpen.GetPathName());
	
}

void CUsbCertPage::OnBptod() //PEM-->DER 
{
	// TODO: Add your control notification handler code here
	char *out;
	//获得输入文件和输出文件
	CString infile,outfile;
	GetDlgItemText(IDC_EDIT_INFILE,infile);
	if(infile=="")
	{
		m_List.AddMsg("请选择输入文件",M_WARING);
		return;
	}
	GetDlgItemText(IDC_EDIT_OUTFILE,outfile);
	if(outfile=="")
	{
		m_List.AddMsg("请指定输出文件",M_WARING);
		return;
	}
	
//	if(CertFormatConver(infile.GetBuffer(0),0,NULL,outfile.GetBuffer(0),DER,out))
//	int FormatConv(char * fileIn,int lenIn,char * fileOut,int outformat)
	if(FormatConv(infile.GetBuffer(0),0,outfile.GetBuffer(0),DER))
	{
		m_List.AddMsg("格式转换成功");
	}
	else
	{
		out=(char *)Get_Func_Err(0);
		m_List.AddMsg(out,M_ERROR);
	}
}


void CUsbCertPage::OnBdtop() //DER-->PEM
{
	// TODO: Add your control notification handler code here
	char *out;
	CString infile,outfile;
	GetDlgItemText(IDC_EDIT_INFILE,infile);
	if(infile=="")
	{
		m_List.AddMsg("请选择输入文件",M_WARING);
		return;
	}
	GetDlgItemText(IDC_EDIT_OUTFILE,outfile);
	if(outfile=="")
	{
		m_List.AddMsg("请指定输出文件",M_WARING);
		return;
	}

//	if(CertFormatConver(infile.GetBuffer(0),0,NULL,outfile.GetBuffer(0),PEM,out))
//	int FormatConv(char * fileIn,int lenIn,char * fileOut,int outformat)
	if(FormatConv(infile.GetBuffer(0),0,outfile.GetBuffer(0),PEM))
	{
		m_List.AddMsg("格式转换成功");
	}
	else
	{
		out=(char *)Get_Func_Err(0);
		m_List.AddMsg(out,M_ERROR);
	}
}


void CUsbCertPage::OnBCheck() 
{
	// TODO: Add your control notification handler code here
	if(n_Type==3)
	{
		char *out;
		CString infile,outfile;
		GetDlgItemText(IDC_EDIT_INFILE,infile);
		if(infile=="")
		{
			m_List.AddMsg("请选择公钥文件",M_WARING);
			return;
		}
		GetDlgItemText(IDC_EDIT_OUTFILE,outfile);
		if(outfile=="")
		{
			m_List.AddMsg("请选择私钥文件",M_WARING);
			return;
		}

//	if(CertPairCheck(infile.GetBuffer(0),outfile.GetBuffer(0),out))
//	int IsPair(char *cert,int certlen,char *key,int keylen)
		if(IsPair(infile.GetBuffer(0),0,outfile.GetBuffer(0),0))
		{
			m_List.AddMsg("公私钥对匹配");
		}
		else
		{
			out=(char *)Get_Func_Err(0);
			m_List.AddMsg(out,M_ERROR);
		}
	}
	else if(n_Type==2)
		m_List.AddMsg("功能未完成");
	else if(n_Type==1)
		OnBdtop();
	else
		OnBptod();
}

⌨️ 快捷键说明

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