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

📄 safedatasetpage.cpp

📁 MiniCA V2.0版本源码。《小型CA系统V2.1含源码》发表以来
💻 CPP
📖 第 1 页 / 共 5 页
字号:

			strPathName.Format("%s\\%s",szTempPath, pDataSafe->cName);
			bSucceed = DecOneFile(m_strEvpPath, strPathName, pDataSafe->dBeginSeek, 
				pDataSafe->dNewLen, pDataSafe->dOldLen, strOut);
		}

		if(bSucceed)
			ShellExecute(this->m_hWnd, "open", strPathName, "", "", SW_SHOWNORMAL);
		else
			AddMsg(strOut, M_ERROR);
	}
	else//展开
	{
		BOOL bRedraw=0;
		if(m_DataSetList.ItemHasChildren(pItem))
		{
			m_DataSetList.SetRedraw(0);
			int nScrollIndex=0;
			if(m_DataSetList.IsCollapsed(pItem))
			{		
				if(m_DataSetList.OnItemExpanding(pItem, nIndex))
				{
					nScrollIndex = m_DataSetList.Expand(pItem, nIndex);
					m_DataSetList.OnItemExpanded(pItem, nIndex);
					bRedraw=1;
				}
			}	
			
			else 
			{
				if(m_DataSetList.OnCollapsing(pItem))
				{
					m_DataSetList.Collapse(pItem);
					m_DataSetList.OnItemCollapsed(pItem);
					bRedraw=1;
				}
			}
			m_DataSetList.SetRedraw(1);
			
			if(bRedraw)
			{
				CRect rc;
				m_DataSetList.GetItemRect(nIndex,rc,LVIR_BOUNDS);
				m_DataSetList.InvalidateRect(rc);
				m_DataSetList.UpdateWindow();
				m_DataSetList.EnsureVisible(nScrollIndex,1);
			}
		}//ItemHasChildren	
	}
	
	*pResult = 0;
}

//只是解密时候用,加密时候结构中保存了路径信息
//给定某个结构信息,附加父信息在其上面
//例如,结构为文件结构,文件名为minica.rar
//父结构肯定为目录结构,目录名为minica
//minica的父结构也存在,目录名为vc
//vc没有分目录
//最后的附加信息为:vc\\minica\\minica.rar
//参数:	pDataSafe - 当前的结构信息
//		uMinPid - 最小父结构ID
//解密时候可能不从根开始解密,这时候需要传递父lpParentItem
CString CSafeDataSetPage::GetPathName(CDataSafe* pDataSafe, 
									  CList<CDataSafe *, CDataSafe *> * pDataList)
{
	CString strAllPath, strPathName;//全部路径

	if(!pDataSafe && !pDataList)
		return strAllPath;

	if(pDataSafe->uParentID == 0)//标示没有父
		strPathName = pDataSafe->cName;
	else
	{
		
		for(CDataSafe* pDataTemp = pDataSafe; ;)
		{
			strPathName = pDataTemp->cName + strPathName;
			strPathName = "\\" + strPathName;
			if(pDataTemp->uParentID == 0)
				break;
			POSITION pos = pDataList->FindIndex( pDataTemp->uParentID - 1);
			if(pos)
			{
				pDataTemp = pDataList->GetAt(pos);
			}
			else
				break;
		}
	}


	strAllPath.Format("%s\\%s", m_strSavePath, strPathName);					//解压到
	if(strAllPath.GetAt(strAllPath.GetLength() - 1) == '\\')
		strAllPath = strAllPath.Left(strAllPath.GetLength() - 1);
	return strAllPath;
}

BOOL CSafeDataSetPage::Mdir(CString strPathName, CString & strInfo)
{
	strPathName += "\\";
	return CMiniCaApp::MakeSureDirectoryPathExists(strPathName);
	/*if(_mkdir(strPathName) == -1)
	{
		if(errno==ENOENT)//目录没有发现
		{
			strInfo.Format("建立目录%s失败!",strPathName);
			return FALSE;
		}
	}*/

}

void CSafeDataSetPage::OnRadio1() //对称加密按钮
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_CHIPNAME)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATIC_PWD)->EnableWindow(TRUE);
	GetDlgItem(IDC_COMBO_CRYPT)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_PWD)->EnableWindow(TRUE);
}

void CSafeDataSetPage::OnRadio2() //信封加密按钮
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_CHIPNAME)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATIC_PWD)->EnableWindow(FALSE);
	GetDlgItem(IDC_COMBO_CRYPT)->EnableWindow(TRUE);
	GetDlgItem(IDC_EDIT_PWD)->EnableWindow(FALSE);
}

void CSafeDataSetPage::OnRadio3() //摘要
{
	// TODO: Add your control notification handler code here
	
}

void CSafeDataSetPage::OnRadio4() //签名
{
	// TODO: Add your control notification handler code here
	
}

void CSafeDataSetPage::OnRadio5() //公钥加密按钮
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_CHIPNAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_STATIC_PWD)->EnableWindow(FALSE);
	GetDlgItem(IDC_COMBO_CRYPT)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_PWD)->EnableWindow(FALSE);
}

void CSafeDataSetPage::OnRadio6() //私钥加密按钮
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_STATIC_CHIPNAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_STATIC_PWD)->EnableWindow(FALSE);
	GetDlgItem(IDC_COMBO_CRYPT)->EnableWindow(FALSE);
	GetDlgItem(IDC_EDIT_PWD)->EnableWindow(FALSE);
}

void CSafeDataSetPage::OnBEnc() 
{
	// TODO: Add your control notification handler code here
	if(pThreadEvpSet != NULL )
		return;
	
	//检测列表中是否有记录
//	int nCount = ;

	if(m_DataSetList.GetCount() == 0)
	{
		AddMsg(MiniCT_1308, M_ERROR);
		return;
	}

	CEvp::SetProgRess(CSafeDataSetPage::m_pProgOne);

	if(m_bIsEnc)//加密
	{
		if(((CButton *)GetDlgItem(IDC_RADIO1))->GetCheck())//对称加密
		{
			m_EncType = CRYPT;
		}
		else if(((CButton *)GetDlgItem(IDC_RADIO2))->GetCheck())//信封加密
		{
			m_EncType = SEAL;
		}
		else if(((CButton *)GetDlgItem(IDC_RADIO3))->GetCheck())//摘要
		{
			m_EncType = DIGEST;
		}
		else if(((CButton *)GetDlgItem(IDC_RADIO4))->GetCheck())//签名
		{
			m_EncType = SIGN;
		}
		else if(((CButton *)GetDlgItem(IDC_RADIO5))->GetCheck())//公钥加密
		{
			m_EncType = PubEnc;
		}
		else if(((CButton *)GetDlgItem(IDC_RADIO6))->GetCheck())//私钥加密
		{
			m_EncType = PrivEnc;
		}
		//出现令存对话框
		CFileDialog dlgOpen(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT /*| OFN_NOCHANGEDIR */,
			MiniCT_1345, NULL);
		dlgOpen.m_ofn.lStructSize = sizeof(OPENFILENAME);
		CString str = MiniCT_1343;
		dlgOpen.m_ofn.lpstrTitle = str;//标题条 LPCTSTR
		if(dlgOpen.DoModal()!=IDOK) return;
		m_strEvpPath = dlgOpen.GetPathName();
		CString strExt = m_strEvpPath.Right(4);
		if(strExt.CollateNoCase(".Evp") != 0)
			m_strEvpPath += ".Evp";
		
	}
	else
	{
		//出现解密到对话框
		if(!SelectPath())
			return;
	}

	pThreadEvpSet = ::AfxBeginThread(_EvpSetThread,this,THREAD_PRIORITY_IDLE);	

}

void CSafeDataSetPage::OnKeydownListDataset(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here
	if(!m_bIsEnc) //解密,不能删除
		return;
	switch(pLVKeyDow->wVKey)
	{
	case VK_DELETE: //只能删除父目录
		{
			int nItem = m_DataSetList.GetSelectedItem();
			if(nItem!=-1)
			{
				CSuperGridCtrl::CTreeItem * pSelItem = m_DataSetList.GetTreeItem(nItem);
				
				CItemInfo * pInfo = m_DataSetList.GetData(pSelItem ); 
				if(pInfo->GetDataSafe()->uParentID != 0) //0为根的父
				{
					return;
				}
				
				//删除拖动链表
				POSITION pos = m_DirName.GetHeadPosition();
				while ( NULL != pos )
				{
					if(m_DirName.GetAt(pos).Compare(pInfo->GetDataSafe()->cPathName) == 0)//删除
					{
						m_DirName.RemoveAt(pos);
						break;
					}
					m_DirName.GetNext(pos);
				}
				
				m_DataSetList.DeleteItemEx(pSelItem, nItem);
			}					
		}
		break;
	}
	
	
	*pResult = 0;
}

//记录结构信息的MAP,在加密解密之前先要枚举列表到MAP中
void CSafeDataSetPage::EnumList(CList<CDataSafe *, CDataSafe *> * pDataList, CList<CDataSafe *, CDataSafe *> * pDirList)
{
	//枚举目录列表加密信息
	POSITION pos = m_DataSetList.GetRootHeadPosition();
	while(pos != NULL)
	{
		CSuperGridCtrl::CTreeItem *pParent = m_DataSetList.GetNextRoot(pos); 
		CSuperGridCtrl::CTreeItem *pItem = pParent;
		CItemInfo* lp = m_DataSetList.GetData(pParent);
		CDataSafe * pDataSafe = new CDataSafe();
		lp->CopyDataSafe(pDataSafe);
		pDataList->AddTail(pDataSafe);
		if(pDirList) //解密时候需要建立目录,此时需要添加目录列表
		{
			if(!pDataSafe->bIsFile)//目录
				pDirList->AddTail(pDataSafe);
		}
		
		//GetNext ....loop through all children 
		for(;;)
		{
			CSuperGridCtrl::CTreeItem *pCur = m_DataSetList.GetNext(pParent, pItem, TRUE, FALSE/*regardless of the item are hidden or not, set to TRUE if only visible items must be included in the search*/);	  
			if(!m_DataSetList.IsChildOf(pParent, pCur))
				break;
			else if(pCur==pItem)
				break;
			CItemInfo* lp = m_DataSetList.GetData(pCur);
			pItem = pCur;//next;
			CDataSafe * pDataSafe = new CDataSafe();
			lp->CopyDataSafe(pDataSafe);
			pDataList->AddTail(pDataSafe);
			if(pDirList) //解密时候需要建立目录,此时需要添加目录列表
			{
				if(!pDataSafe->bIsFile)//目录
					pDirList->AddTail(pDataSafe);
			}

		}
	}
}

void CSafeDataSetPage::CleanList(CList<CDataSafe *, CDataSafe *> * pDataList)
{
	POSITION pos = pDataList->GetHeadPosition();
	while(pos != NULL)
	{
		CDataSafe* pDataSafe = pDataList->GetNext(pos);
		if(pDataSafe)
			delete pDataSafe;
	}

}

void CSafeDataSetPage::DoCrypt()
{
	CString strCpName, strPwd;
	GetDlgItemText(IDC_COMBO_CRYPT,strCpName);
	GetDlgItemText(IDC_EDIT_PWD,strPwd);
	if(strCpName.IsEmpty() || strPwd.IsEmpty())
	{
		AddMsg(MiniCT_1330, M_ERROR);//请输入加密密钥和算法名称
		pThreadEvpSet = NULL;
		return;
	}
	CString outMsg;
	if(!Crypt(strCpName, strPwd, m_strEvpPath, outMsg))
	{
		AddMsg(outMsg, M_ERROR);
	}
	else
		AddMsg(MiniCT_1331);//对称加密成功
	pThreadEvpSet = NULL;
	
}

void CSafeDataSetPage::DoSeal()
{
	//创建合法用户公钥链
	CEvp::stuCertLink * pCertLink = NULL;
	int nCount = 0;
	if(m_pPageCdb->GetCertPair(CSafeDataCdbPage::SEAL, TRUE, m_strKey, 
		m_lenKey,m_p12Pwd,&((CMiniMainDlg *)m_pParent)->m_ListBox))//得到公钥
	{
		//可能为多证书,这时查找;,然后添加每一个
		if(m_lenKey == 0) //外部证书
		{
			CString strSub,
				    strPath;
			while(AfxExtractSubString(strSub, m_strKey, nCount++, ';'))	//未公开 分解字符串
			{
				if(nCount == 1) //第一个文件,取得路径
				{
					int nPos = strSub.ReverseFind('\\');
					strPath = strSub.Left(nPos + 1);//附带
					strSub.TrimLeft();
					pCertLink->AddCert(pCertLink, strSub, m_lenKey);
				}
				else
				{
					strSub.TrimLeft();
					pCertLink->AddCert(pCertLink, strPath + strSub, m_lenKey);
				}

			}
		}
		else
			pCertLink->AddCert(pCertLink, m_strKey, m_lenKey);
	}
	
	CString strCpName;
	GetDlgItemText(IDC_COMBO_CRYPT,strCpName);
	if(strCpName.IsEmpty())
	{
		AddMsg(MiniCT_1332, M_ERROR); //请输入加密算法名称
		pThreadEvpSet = NULL;
		return;
	}
	CString outMsg;
	if(!Seal(pCertLink, strCpName, m_strEvpPath, outMsg))
	{
		AddMsg(outMsg, M_ERROR);
	}
	else
		AddMsg(MiniCT_1333);//封装信封成功
	pCertLink->RemoveAll(pCertLink);
	pThreadEvpSet = NULL;
}

void CSafeDataSetPage::DoRSAPubEnc()
{
	CString outStr;
	if(m_pPageCdb->GetCertPair(CSafeDataCdbPage::PubEnc, TRUE, m_strKey,
		m_lenKey,m_p12Pwd, &((CMiniMainDlg *)m_pParent)->m_ListBox))//得到公钥
	{
		if(!RSAPubEnc((UCHAR *)m_strKey, m_lenKey, m_strEvpPath, outStr))
		{
			AddMsg(outStr, M_ERROR);
		}
		else
			AddMsg(MiniCT_1334);//公钥加密成功
	}
	pThreadEvpSet = NULL;
}

void CSafeDataSetPage::DoRSAPrivEnc()
{
	CString outStr;
	if(m_pPageCdb->GetCertPair(CSafeDataCdbPage::PubEnc, FALSE, m_strKey, 
		m_lenKey, m_p12Pwd, &((CMiniMainDlg *)m_pParent)->m_ListBox))//得到私钥
	{ 
 		if(!RSAPrivEnc((UCHAR *)m_strKey, m_lenKey, m_p12Pwd, m_strEvpPath, outStr))
		{
			AddMsg(outStr, M_ERROR);
		}
		else
			AddMsg(MiniCT_1335);//私钥加密成功
	}
	pThreadEvpSet = NULL;
}

void CSafeDataSetPage::DoDecCrypt()
{
	CString strCpName, strPwd, outStr;
	GetDlgItemText(IDC_COMBO_CRYPT, strCpName);
	GetDlgItemText(IDC_EDIT_PWD, strPwd);
	CString strEvpFile(m_strEvpPath);
	if(strPwd.IsEmpty() || strCpName.IsEmpty())
	{
		AddMsg(MiniCT_1336, M_ERROR);		 //请选择算法并输入加密密码
		pThreadEvpSet = NULL;
		return;
	}
	if(!DecCrypt(strCpName, strPwd, strEvpFile, outStr))
	{
		AddMsg(outStr, M_ERROR);
	}
	else
		AddMsg(MiniCT_1337); //对称解密成功
	pThreadEvpSet = NULL;
	
}

void CSafeDataSetPage::DoOpenSeal()
{
	CString strCpName, outStr;
	GetDlgItemText(IDC_COMBO_CRYPT, strCpName);
	CString strEvpFile(m_strEvpPath);
	if(strCpName.IsEmpty())
	{
		AddMsg(MiniCT_1338, M_ERROR);		 //"请选择算法"
		pThreadEvpSet = NULL;
		return;
	}
	if(m_pPageCdb->GetCertPair(CSafeDataCdbPage::SEAL, FALSE, m_strKey, m_lenKey, m_p12Pwd,
		&((CMiniMainDlg *)m_pParent)->m_ListBox))//得到私钥
	{
		if(!OpenSeal(m_strKey, m_lenKey, m_p12Pwd.GetBuffer(0), strCpName, strEvpFile, outStr))
		{
			AddMsg(outStr, M_ERROR);
		}
		else
			AddMsg(MiniCT_1339); //拆封信封成功
		m_p12Pwd.ReleaseBuffer();
	}
	pThreadEvpSet = NULL;
}

void CSafeDataSetPage::DoRSAPr

⌨️ 快捷键说明

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