// EncScur.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "EncScur.h" #include "EditKey.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "dclientDlg.h" ///////////////////////////////////////////////////////////////////////////// // CEncryptSecurty property page IMPLEMENT_DYNCREATE(CEncryptSecurty, CPropertyPage) CEncryptSecurty::CEncryptSecurty() : CPropertyPage(CEncryptSecurty::IDD) { //{{AFX_DATA_INIT(CEncryptSecurty) //}}AFX_DATA_INIT } CEncryptSecurty::~CEncryptSecurty() { } void CEncryptSecurty::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CEncryptSecurty) DDX_Control(pDX, IDC_LIST_ENCRYPT_KEYS, m_lstEncryptKey); DDX_Control(pDX, IDC_COMBO_SIGN_ALGORTHM, m_cmbSignAlgrthm); DDX_Control(pDX, IDC_COMBO_ENCRYPT_ALGRTHM, m_cmbEncryptAlgrthm); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CEncryptSecurty, CPropertyPage) //{{AFX_MSG_MAP(CEncryptSecurty) ON_BN_CLICKED(IDC_ENCRYPT_EDIT, OnEncryptEdit) ON_BN_CLICKED(IDC_ENCRYPT_GENERATE, OnEncryptGenerate) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CEncryptSecurty message handlers BOOL CEncryptSecurty::OnInitDialog() { CPropertyPage::OnInitDialog(); m_cmbSignAlgrthm.InsertString(0, "ISCL_MAC_NONE"); m_cmbSignAlgrthm.InsertString(1, "ISCL_MAC_MD5"); m_cmbSignAlgrthm.InsertString(2, "ISCL_MAC_DESMAC"); m_cmbSignAlgrthm.SetCurSel(m_pDclientDlg->m_lSigningAlgorithmIndex); //////////////////////////////////////////////////////////////// m_cmbEncryptAlgrthm.InsertString(0, "ISCL_ENCRYPT_NONE"); m_cmbEncryptAlgrthm.InsertString(1, "ISCL_ENCRYPT_DESCBC"); m_cmbEncryptAlgrthm.SetCurSel(m_pDclientDlg->m_lEncrAlgorithmIndex); //////////////////////////////////////////////////////////////// LVCOLUMN lstCol; lstCol.mask = LVCF_WIDTH | LVCF_TEXT; lstCol.fmt = LVCFMT_LEFT; lstCol.cx = 50; lstCol.pszText = "Index"; //ignored lstCol.cchTextMax = 2; lstCol.iSubItem = 1; m_lstEncryptKey.InsertColumn(0, &lstCol); memset(&lstCol, 0, sizeof(LVCOLUMN)); lstCol.mask = LVCF_WIDTH | LVCF_TEXT; lstCol.fmt = LVCFMT_LEFT; lstCol.cx = 160; lstCol.pszText = "Value"; //ignored lstCol.cchTextMax = 20; m_lstEncryptKey.InsertColumn(1, &lstCol); //////////////////////////////////////////////////////////////// LVITEM lvItem; for(int i=0; i<8; ++i) { CString strIndex; char szValue[20]; strIndex.Format("%d", i+1); sprintf(szValue, "%I64X", m_pDclientDlg->m_ISCLEncrKeys[i]); memset(&lvItem, 0, sizeof(LVITEM)); lvItem.mask = LVIF_TEXT; lvItem.iItem = i; lvItem.iSubItem = 0; lvItem.pszText = strIndex.GetBuffer(0); //ignored lvItem.cchTextMax = 2; m_lstEncryptKey.InsertItem(&lvItem); lvItem.iItem = i; lvItem.iSubItem = 1; lvItem.pszText = szValue; //ignored lvItem.cchTextMax = 20; m_lstEncryptKey.SetItem(&lvItem); } m_lstEncryptKey.SetItemState(m_pDclientDlg->m_lCurrentISCLEncrKey-1, LVIS_SELECTED, LVIS_SELECTED); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CEncryptSecurty::OnEncryptEdit() { CString csText; int iIndex = m_lstEncryptKey.GetNextItem(-1, LVNI_SELECTED); csText = m_lstEncryptKey.GetItemText(iIndex, 1); CEditKey EditKey(csText); if (EditKey.DoModal() == IDOK) { LVITEM lvItem; memset(&lvItem, 0, sizeof(LVITEM)); lvItem.mask = LVIF_TEXT; lvItem.iItem = iIndex; lvItem.iSubItem = 1; lvItem.pszText = (LPSTR)(LPCTSTR)EditKey.m_csKey; //ignored lvItem.cchTextMax = 20; m_lstEncryptKey.SetItem(&lvItem); } } void CEncryptSecurty::OnEncryptGenerate() { srand(rand() + (unsigned)time(NULL)); for(int i=0; i<8; ++i) { char szValue[20]; __int64 RandNo64 = 0; for(int j=0; j<8; ++j) RandNo64 = (RandNo64 << 8) | (0x0FF & rand()); sprintf(szValue, "%I64X", RandNo64); m_lstEncryptKey.SetItemText(i, 1, szValue); } } void CEncryptSecurty::OnOK() { m_pDclientDlg->m_lSigningAlgorithmIndex = m_cmbSignAlgrthm.GetCurSel(); m_pDclientDlg->m_lEncrAlgorithmIndex = m_cmbEncryptAlgrthm.GetCurSel(); for(int i=0; i<8; ++i) { CString strValue = m_lstEncryptKey.GetItemText(i, 1); sscanf(LPCTSTR(strValue), "%I64X", &(m_pDclientDlg->m_ISCLEncrKeys[i])); } m_pDclientDlg->m_lCurrentISCLEncrKey = m_lstEncryptKey.GetNextItem(-1, LVNI_SELECTED)+1; CPropertyPage::OnOK(); }