GetEncrypInfoDlg.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // GetEncrypInfoDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "GetEncrypInfo.h"
  5. #include "GetEncrypInfoDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. COLORREF g_rgb = RGB(226, 220, 202); // 米黄色;
  10. COLORREF g_rgb1 = RGB(238, 238, 242);
  11. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  12. class CAboutDlg : public CDialog
  13. {
  14. public:
  15. CAboutDlg();
  16. // 对话框数据
  17. enum { IDD = IDD_ABOUTBOX };
  18. protected:
  19. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  20. // 实现
  21. protected:
  22. DECLARE_MESSAGE_MAP()
  23. };
  24. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  25. {
  26. }
  27. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. }
  31. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  32. END_MESSAGE_MAP()
  33. // CGetEncrypInfoDlg 对话框
  34. CGetEncrypInfoDlg::CGetEncrypInfoDlg(CWnd* pParent /*=NULL*/)
  35. : CDialog(CGetEncrypInfoDlg::IDD, pParent)
  36. {
  37. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  38. }
  39. void CGetEncrypInfoDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. }
  43. BEGIN_MESSAGE_MAP(CGetEncrypInfoDlg, CDialog)
  44. ON_WM_SYSCOMMAND()
  45. ON_WM_PAINT()
  46. ON_WM_QUERYDRAGICON()
  47. //}}AFX_MSG_MAP
  48. ON_WM_CTLCOLOR()
  49. ON_BN_CLICKED(BTN_ADVANCE, &CGetEncrypInfoDlg::OnBnClickedAdvance)
  50. END_MESSAGE_MAP()
  51. // CGetEncrypInfoDlg 消息处理程序
  52. BOOL CGetEncrypInfoDlg::OnInitDialog()
  53. {
  54. CDialog::OnInitDialog();
  55. // 将“关于...”菜单项添加到系统菜单中。
  56. // IDM_ABOUTBOX 必须在系统命令范围内。
  57. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  58. ASSERT(IDM_ABOUTBOX < 0xF000);
  59. CMenu* pSysMenu = GetSystemMenu(FALSE);
  60. if (pSysMenu != NULL)
  61. {
  62. BOOL bNameValid;
  63. CString strAboutMenu;
  64. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  65. ASSERT(bNameValid);
  66. if (!strAboutMenu.IsEmpty())
  67. {
  68. pSysMenu->AppendMenu(MF_SEPARATOR);
  69. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  70. }
  71. }
  72. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  73. // 执行此操作
  74. SetIcon(m_hIcon, TRUE); // 设置大图标
  75. SetIcon(m_hIcon, FALSE); // 设置小图标
  76. // TODO: 在此添加额外的初始化代码
  77. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  78. }
  79. void CGetEncrypInfoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  80. {
  81. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  82. {
  83. CAboutDlg dlgAbout;
  84. dlgAbout.DoModal();
  85. }
  86. else
  87. {
  88. CDialog::OnSysCommand(nID, lParam);
  89. }
  90. }
  91. // 如果向对话框添加最小化按钮,则需要下面的代码
  92. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  93. // 这将由框架自动完成。
  94. void CGetEncrypInfoDlg::OnPaint()
  95. {
  96. if (IsIconic())
  97. {
  98. CPaintDC dc(this); // 用于绘制的设备上下文
  99. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  100. // 使图标在工作区矩形中居中
  101. int cxIcon = GetSystemMetrics(SM_CXICON);
  102. int cyIcon = GetSystemMetrics(SM_CYICON);
  103. CRect rect;
  104. GetClientRect(&rect);
  105. int x = (rect.Width() - cxIcon + 1) / 2;
  106. int y = (rect.Height() - cyIcon + 1) / 2;
  107. // 绘制图标
  108. dc.DrawIcon(x, y, m_hIcon);
  109. }
  110. else
  111. {
  112. CDialog::OnPaint();
  113. }
  114. }
  115. //当用户拖动最小化窗口时系统调用此函数取得光标
  116. //显示。
  117. HCURSOR CGetEncrypInfoDlg::OnQueryDragIcon()
  118. {
  119. return static_cast<HCURSOR>(m_hIcon);
  120. }
  121. void CGetEncrypInfoDlg::OnBnClickedAdvance()
  122. {
  123. // TODO: 在此添加控件通知处理程序代码
  124. GetDlgItem(BTN_ADVANCE)->EnableWindow(FALSE);
  125. if (!Encryptlockkernel::InitEncryptlock())
  126. AfxMessageBox(_T("初始化加密锁失败!"));
  127. else
  128. AfxMessageBox(_T("初始化加密锁成功!"));
  129. Sleep(10);
  130. Encryptlockkernel::g_bUSE_NEWPASSWORD = FALSE;
  131. Encryptlockkernel::ReSetPassWord();
  132. int nRet = -1;
  133. DWORD dwShortKey = 0;
  134. int nVersion = -1;
  135. CHAR szKeyPath[MAX_PATH] = { 0 };
  136. INT nStartPort = 0;
  137. if (!Encryptlockkernel::FindYtUSB(dwShortKey, nVersion, szKeyPath, nStartPort))
  138. return ;
  139. if (dwShortKey == -1)
  140. {
  141. // 不是域天智能锁;
  142. AfxMessageBox(_T("不是域天智能锁!!!"));
  143. GetDlgItem(BTN_ADVANCE)->EnableWindow();
  144. return ;
  145. }
  146. AfxMessageBox(_T("初始化加密狗读写密码!!!"));
  147. nRet = SetReadPassword("FFFFFFFF", "FFFFFFFF", Encryptlockkernel::g_pHReadPassWord, Encryptlockkernel::g_pLReadPassWord, szKeyPath);
  148. if (nRet != 0) {
  149. AfxMessageBox(Encryptlockkernel::GetYtUSBKey32ErrInfo(nRet));
  150. GetDlgItem(BTN_ADVANCE)->EnableWindow();
  151. return ;
  152. }
  153. nRet = SetWritePassword("FFFFFFFF", "FFFFFFFF", Encryptlockkernel::g_pHWritePassWord, Encryptlockkernel::g_pLWritePassWord, szKeyPath);
  154. if (nRet != 0) {
  155. AfxMessageBox(Encryptlockkernel::GetYtUSBKey32ErrInfo(nRet));
  156. GetDlgItem(BTN_ADVANCE)->EnableWindow();
  157. return ;
  158. }
  159. // 297是域名值;
  160. // 生成域名串 = 日期 + 短ID;
  161. CHAR szDomain[ENCRYPT_BLOCK_LEN] = { 0 }; // 包含结束符;
  162. CTime tt = CTime::GetCurrentTime();
  163. sprintf_s(szDomain, "%04d%02d%02d%d.ly.com", tt.GetYear(), tt.GetMonth(), tt.GetDay(), dwShortKey);
  164. if ( ( nRet = YtWriteString(szDomain, 297, Encryptlockkernel::g_pHWritePassWord, Encryptlockkernel::g_pLWritePassWord, szKeyPath)) <= 0)
  165. {
  166. // 生成域名错误;
  167. AfxMessageBox(Encryptlockkernel::GetYtUSBKey32ErrInfo(nRet));
  168. GetDlgItem(BTN_ADVANCE)->EnableWindow();
  169. return ;
  170. }
  171. AfxMessageBox(_T("初始化加密狗成功!!!"));
  172. exit(0);
  173. }