因为客户需要对本产品的协议保密不公开,所以往往会将自己的机密算法通过dll打包,只为开发团队提供一个接口。
这样就可以避免开发人员公开自己的机密算法。
以下举例,作为开发团队,如何通过客户的dll包实现产品加密算法:
1 // FobsignupDlg.cpp : implementation file 2 // 3 4 #include "stdafx.h" 5 #include "Fobsignup.h" 6 #include "FobsignupDlg.h" 7 #include "afxdialogex.h" 8 9 #ifdef _DEBUG 10 #define new DEBUG_NEW 11 #endif 12 typedef int(*PFUN)(const unsigned int fobIdLen 13 , const unsigned int maxPepArrayLen 14 , const unsigned int maxRkeArrayLen 15 , const unsigned char *encryptedFobId 16 , unsigned int *actualPepArrayLen 17 , unsigned int *actualRkeArrayLen 18 , unsigned char *dtEncryptedPepArray 19 , unsigned char *dtEncryptedRkeArray); 20 21 typedef void(*AESFUN)(unsigned char *pskey, unsigned char *blk); 22 //e.g, input="123456"--(length=6)-->output={0x12,0x34,0x56} 23 typedef int(*C2HFUN)(char*input, unsigned char *output, int length); 24 25 unsigned char dll_key_fob[16] = { 0x56, 0x38, 0x97, 0x3f, 0x56, 0x70, 0x22, 0x88, 0x3b, 0x52, 0xfe, 0x5a, 0x01, 0x32, 0x08, 0x49 }; 26 unsigned char dll_key_PEP[16] = { 0x13, 0xff, 0x13, 0x84, 0x43, 0x86, 0x43, 0x4a, 0x23, 0x53, 0xe6, 0x54, 0xd3, 0x02, 0x00, 0x34 }; 27 unsigned char dll_key_RKE[16] = { 0x15, 0x42, 0x71, 0x73, 0x6a, 0x41, 0xe3, 0x45, 0xde, 0x40, 0xba, 0x34, 0x42, 0x82, 0xaa, 0xe2 }; 28 29 unsigned char bcm_key_PEP[16] = { 0x18, 0x92, 0x14, 0x81, 0x89, 0xf2, 0x4f, 0xa4, 0x92, 0x52, 0xfe, 0x5a, 0x4e, 0x32, 0xcc, 0x3d }; 30 unsigned char bcm_key_RKE[16] = { 0x12, 0x52, 0x63, 0x54, 0x25, 0x4b, 0xc3, 0x4b, 0x23, 0x00, 0xdd, 0xbb, 0xc3, 0x82, 0xfd, 0xf4 }; 31 //CRC-8 for ATM HEC (x8+x2+x+1) 32 unsigned char cal_crc(unsigned char *vptr, unsigned char len) 33 { 34 const unsigned char *data = vptr; 35 unsigned int crc = 0; 36 int i, j; 37 for (j = len; j; j--, data++) 38 { 39 crc ^= (*data << 8); 40 for (i = 8; i; i--) 41 { 42 if (crc & 0x8000) 43 crc ^= (unsigned int)(0x1070 << 3); 44 crc <<= 1; 45 } 46 } 47 return (unsigned char)(crc >> 8); 48 } 49 // CAboutDlg dialog used for App About 50 51 class CAboutDlg : public CDialogEx 52 { 53 public: 54 CAboutDlg(); 55 56 // Dialog Data 57 enum { IDD = IDD_ABOUTBOX }; 58 59 protected: 60 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 61 62 // Implementation 63 protected: 64 DECLARE_MESSAGE_MAP() 65 }; 66 67 CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) 68 { 69 } 70 71 void CAboutDlg::DoDataExchange(CDataExchange* pDX) 72 { 73 CDialogEx::DoDataExchange(pDX); 74 } 75 76 BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) 77 END_MESSAGE_MAP() 78 79 80 // CFobsignupDlg dialog 81 82 83 84 CFobsignupDlg::CFobsignupDlg(CWnd* pParent /*=NULL*/) 85 : CDialogEx(CFobsignupDlg::IDD, pParent) 86 , m_Edit1(_T("")) 87 , m_Edit2(_T("")) 88 , m_Edit3(_T("")) 89 , m_Edit4(_T("")) 90 , m_Edit5(_T("")) 91 , m_Edit6(_T("")) 92 , m_Edit7(_T("")) 93 , m_Edit8(_T("")) 94 , m_Edit9(_T("")) 95 { 96 m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1); //IDR_MAINFRAME 97 } 98 99 void CFobsignupDlg::DoDataExchange(CDataExchange* pDX) 100 { 101 CDialogEx::DoDataExchange(pDX); 102 DDX_Text(pDX, IDC_EDIT1, m_Edit1); 103 DDX_Text(pDX, IDC_EDIT2, m_Edit2); 104 DDX_Text(pDX, IDC_EDIT3, m_Edit3); 105 DDX_Text(pDX, IDC_EDIT4, m_Edit4); 106 DDX_Text(pDX, IDC_EDIT5, m_Edit5); 107 DDX_Text(pDX, IDC_EDIT6, m_Edit6); 108 DDX_Text(pDX, IDC_EDIT7, m_Edit7); 109 DDX_Text(pDX, IDC_EDIT8, m_Edit8); 110 DDX_Text(pDX, IDC_EDIT9, m_Edit9); 111 // DDX_Control(pDX, IDC_MSCOMM1, m_mscom); 112 } 113 114 BEGIN_MESSAGE_MAP(CFobsignupDlg, CDialogEx) 115 ON_WM_SYSCOMMAND() 116 ON_WM_PAINT() 117 ON_WM_QUERYDRAGICON() 118 ON_BN_CLICKED(IDC_BUTTON1, &CFobsignupDlg::create_BN_CLICKED) 119 ON_BN_CLICKED(IDC_BUTTON2, &CFobsignupDlg::Clear_BN_CLICKED) 120 // ON_BN_CLICKED(IDC_BUTTON3, &CFobsignupDlg::OnBnClickedButton3) 121 ON_BN_CLICKED(IDC_BUTTON3, &CFobsignupDlg::write_BN_CLICKED) 122 ON_BN_CLICKED(IDC_BUTTON4, &CFobsignupDlg::Open_Close_BN_CLICKED) 123 ON_BN_CLICKED(IDC_CHECK1, &CFobsignupDlg::checkBox1_BN_CLICKED) 124 ON_BN_CLICKED(IDC_CHECK2, &CFobsignupDlg::checkBox2_BN_CLICKED) 125 ON_BN_CLICKED(IDC_CHECK3, &CFobsignupDlg::checkBox3_BN_CLICKED) 126 ON_BN_CLICKED(IDC_CHECK4, &CFobsignupDlg::checkBox4_BN_CLICKED) 127 ON_BN_CLICKED(IDC_CHECK5, &CFobsignupDlg::checkBox5_BN_CLICKED) 128 ON_BN_CLICKED(IDC_CHECK6, &CFobsignupDlg::checkBox6_BN_CLICKED) 129 ON_BN_CLICKED(IDC_CHECK7, &CFobsignupDlg::checkBox7_BN_CLICKED) 130 ON_BN_CLICKED(IDC_CHECK8, &CFobsignupDlg::checkBox8_BN_CLICKED) 131 END_MESSAGE_MAP() 132 133 134 // CFobsignupDlg message handlers 135 136 BOOL CFobsignupDlg::OnInitDialog() 137 { 138 CDialogEx::OnInitDialog(); 139 140 // Add "About..." menu item to system menu. 141 142 // IDM_ABOUTBOX must be in the system command range. 143 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); 144 ASSERT(IDM_ABOUTBOX < 0xF000); 145 146 CMenu* pSysMenu = GetSystemMenu(FALSE); 147 if (pSysMenu != NULL) 148 { 149 BOOL bNameValid; 150 CString strAboutMenu; 151 bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); 152 ASSERT(bNameValid); 153 if (!strAboutMenu.IsEmpty()) 154 { 155 pSysMenu->AppendMenu(MF_SEPARATOR); 156 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); 157 } 158 } 159 160 // Set the icon for this dialog. The framework does this automatically 161 // when the application's main window is not a dialog 162 SetIcon(m_hIcon, TRUE); // Set big icon 163 SetIcon(m_hIcon, FALSE); // Set small icon 164 165 // TODO: Add extra initialization here 166 CEdit *pEdit = (CEdit*)(this)->GetDlgItem(IDC_EDIT1); 167 pEdit->SetLimitText(24); 168 CComboBox* pct = (CComboBox *)this->GetDlgItem(IDC_COMBO1); 169 CComboBox* pport = (CComboBox *)this->GetDlgItem(IDC_COMBO2); 170 CComboBox* pbaud = (CComboBox *)this->GetDlgItem(IDC_COMBO3); 171 pct->SetCurSel(0); 172 pport->SetCurSel(1); 173 pbaud->SetCurSel(2); 174 return TRUE; // return TRUE unless you set the focus to a control 175 } 176 177 void CFobsignupDlg::OnSysCommand(UINT nID, LPARAM lParam) 178 { 179 if ((nID & 0xFFF0) == IDM_ABOUTBOX) 180 { 181 CAboutDlg dlgAbout; 182 dlgAbout.DoModal(); 183 } 184 else 185 { 186 CDialogEx::OnSysCommand(nID, lParam); 187 } 188 } 189 190 // If you add a minimize button to your dialog, you will need the code below 191 // to draw the icon. For MFC applications using the document/view model, 192 // this is automatically done for you by the framework. 193 194 void CFobsignupDlg::OnPaint() 195 { 196 if (IsIconic()) 197 { 198 CPaintDC dc(this); // device context for painting 199 200 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); 201 202 // Center icon in client rectangle 203 int cxIcon = GetSystemMetrics(SM_CXICON); 204 int cyIcon = GetSystemMetrics(SM_CYICON); 205 CRect rect; 206 GetClientRect(&rect); 207 int x = (rect.Width() - cxIcon + 1) / 2; 208 int y = (rect.Height() - cyIcon + 1) / 2; 209 210 // Draw the icon 211 dc.DrawIcon(x, y, m_hIcon); 212 } 213 else 214 { 215 CDialogEx::OnPaint(); 216 } 217 } 218 219 // The system calls this function to obtain the cursor to display while the user drags 220 // the minimized window. 221 HCURSOR CFobsignupDlg::OnQueryDragIcon() 222 { 223 return static_cast<HCURSOR>(m_hIcon); 224 } 225 226 227 228 void CFobsignupDlg::create_BN_CLICKED() 229 { 230 // TODO: Add your control notification handler code here 231 char buf[50]; 232 unsigned char chr_buf[12]; 233 unsigned char fob_buf[16]; 234 unsigned char pep_buf[16]; 235 unsigned char rke_buf[16]; 236 unsigned char message_buf[49]; 237 //unsigned char key_buf[16]; 238 int i, k, result; 239 unsigned int peplen = 0, rkelen = 0; 240 unsigned int index; 241 CString str; 242 CString str_show(fob_buf); 243 CButton*pbutton; 244 TCHAR chCurDir[MAX_PATH] = { 0 }; 245 GetCurrentDirectory(MAX_PATH, chCurDir); 246 SetCurrentDirectory(_T("C:\Windows")); 247 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 248 //get context from edit1 249 UpdateData(true); 250 GetDlgItem(IDC_EDIT1)->GetWindowText(str); 251 strcpy(buf, str); 252 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 253 if (!ToChar(buf, fob_buf, 24)) 254 { 255 AfxMessageBox("data invalid."); 256 } 257 else 258 { 259 fob_buf[12] = 0; 260 fob_buf[13] = 0; 261 fob_buf[14] = 0; 262 fob_buf[15] = 0; 263 m_Edit1 = ""; 264 for (i = 0,index=0; i < 12; i++) 265 { 266 if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED) 267 { 268 message_buf[index++] = fob_buf[11-i] ^ 0x38; 269 str_show.Format("%X", fob_buf[11-i]); 270 } 271 else 272 { 273 message_buf[index++] = fob_buf[i] ^ 0x38; 274 str_show.Format("%X", fob_buf[i]); 275 } 276 chr_buf[i] = fob_buf[i]; 277 k = strlen(str_show); 278 if (k == 0) 279 { 280 m_Edit1 = "00"; 281 } 282 else if (k == 1) 283 { 284 m_Edit1 += "0"; 285 m_Edit1 += str_show; 286 } 287 else 288 { 289 m_Edit1 += str_show; 290 } 291 } 292 if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED) 293 { 294 for (i = 0; i < 12; i++) 295 { 296 fob_buf[i] = chr_buf[11 - i]; 297 } 298 pbutton = (CButton*)GetDlgItem(IDC_CHECK1); 299 pbutton->SetCheck(false); 300 } 301 if (IsDlgButtonChecked(IDC_CHECK2) == BST_CHECKED) 302 { 303 pbutton = (CButton*)GetDlgItem(IDC_CHECK2); 304 pbutton->SetCheck(false); 305 } 306 if (IsDlgButtonChecked(IDC_CHECK3) == BST_CHECKED) 307 { 308 pbutton = (CButton*)GetDlgItem(IDC_CHECK3); 309 pbutton->SetCheck(false); 310 } 311 if (IsDlgButtonChecked(IDC_CHECK4) == BST_CHECKED) 312 { 313 pbutton = (CButton*)GetDlgItem(IDC_CHECK4); 314 pbutton->SetCheck(false); 315 } 316 if (IsDlgButtonChecked(IDC_CHECK5) == BST_CHECKED) 317 { 318 pbutton = (CButton*)GetDlgItem(IDC_CHECK5); 319 pbutton->SetCheck(false); 320 } 321 if (IsDlgButtonChecked(IDC_CHECK6) == BST_CHECKED) 322 { 323 pbutton = (CButton*)GetDlgItem(IDC_CHECK6); 324 pbutton->SetCheck(false); 325 } 326 if (IsDlgButtonChecked(IDC_CHECK7) == BST_CHECKED) 327 { 328 pbutton = (CButton*)GetDlgItem(IDC_CHECK7); 329 pbutton->SetCheck(false); 330 } 331 if (IsDlgButtonChecked(IDC_CHECK8) == BST_CHECKED) 332 { 333 pbutton = (CButton*)GetDlgItem(IDC_CHECK8); 334 pbutton->SetCheck(false); 335 } 336 AESFUN m_ase = (AESFUN)::GetProcAddress(hModule, "AesEncrypt"); 337 m_ase(dll_key_fob, fob_buf); 338 m_Edit2 = m_Edit3 = m_Edit4 = m_Edit5 = m_Edit6 = m_Edit7 = m_Edit8 = m_Edit9 = ""; 339 for (i = 0; i < 16; i++) 340 { 341 str_show.Format("%X", fob_buf[i]); 342 k = strlen(str_show); 343 if (k == 0) 344 { 345 m_Edit2 = "00"; 346 } 347 else if (k == 1) 348 { 349 m_Edit2 += "0"; 350 m_Edit2 += str_show; 351 } 352 else 353 { 354 m_Edit2 += str_show; 355 } 356 } 357 hModule = ::LoadLibrary(_T("LaMotta FOB Signup_1.1_REL.dll")); 358 PFUN m_dll = (PFUN)::GetProcAddress(hModule, "FobSignup"); 359 result = m_dll(16, 16, 16, fob_buf, &peplen, &rkelen, pep_buf, rke_buf); 360 if (result == 0) 361 { 362 for (i = 0; i < 16; i++) 363 { 364 str_show.Format("%X", pep_buf[i]); 365 k = strlen(str_show); 366 if (k == 0) 367 { 368 m_Edit3 = "00"; 369 } 370 else if (k == 1) 371 { 372 m_Edit3 += "0"; 373 m_Edit3 += str_show; 374 } 375 else 376 { 377 m_Edit3 += str_show; 378 } 379 str_show.Format("%X", rke_buf[i]); 380 k = strlen(str_show); 381 if (k == 0) 382 { 383 m_Edit4 = "00"; 384 } 385 else if (k == 1) 386 { 387 m_Edit4 += "0"; 388 m_Edit4 += str_show; 389 } 390 else 391 { 392 m_Edit4 += str_show; 393 } 394 } 395 hModule = ::LoadLibrary(_T("AES_DLL.dll")); 396 m_ase = (AESFUN)::GetProcAddress(hModule, "ContraryAesEncrypt"); 397 m_ase(dll_key_PEP, pep_buf); 398 m_ase(dll_key_RKE, rke_buf); 399 for (i = 0; i < 16; i++) 400 { 401 str_show.Format("%X", pep_buf[i]); 402 k = strlen(str_show); 403 if (k == 0) 404 { 405 m_Edit5 = "00"; 406 } 407 else if (k == 1) 408 { 409 m_Edit5 += "0"; 410 m_Edit5 += str_show; 411 } 412 else 413 { 414 m_Edit5 += str_show; 415 } 416 str_show.Format("%X", rke_buf[i]); 417 k = strlen(str_show); 418 if (k == 0) 419 { 420 m_Edit6 = "00"; 421 } 422 else if (k == 1) 423 { 424 m_Edit6 += "0"; 425 m_Edit6 += str_show; 426 } 427 else 428 { 429 m_Edit6 += str_show; 430 } 431 } 432 m_ase(bcm_key_PEP, pep_buf); 433 m_ase(bcm_key_RKE, rke_buf); 434 for (i = 0; i < 16; i++) 435 { 436 message_buf[index++] = pep_buf[i] ^ 0x38; 437 str_show.Format("%X", pep_buf[i]); 438 k = strlen(str_show); 439 if (k == 0) 440 { 441 m_Edit7 = "00"; 442 } 443 else if (k == 1) 444 { 445 m_Edit7 += "0"; 446 m_Edit7 += str_show; 447 } 448 else 449 { 450 m_Edit7 += str_show; 451 } 452 message_buf[index + 15] = rke_buf[i] ^ 0x38; 453 str_show.Format("%X", rke_buf[i]); 454 k = strlen(str_show); 455 if (k == 0) 456 { 457 m_Edit8 = "00"; 458 } 459 else if (k == 1) 460 { 461 m_Edit8 += "0"; 462 m_Edit8 += str_show; 463 } 464 else 465 { 466 m_Edit8 += str_show; 467 } 468 } 469 index += 16; 470 message_buf[index] = cal_crc(message_buf, index) ^ 0x83; 471 for (i = 0; i < int(index + 1); i++) 472 { 473 str_show.Format("%X", message_buf[i]); 474 k = strlen(str_show); 475 if (k == 0) 476 { 477 m_Edit9 = "00"; 478 } 479 else if (k == 1) 480 { 481 m_Edit9 += "0"; 482 m_Edit9 += str_show; 483 } 484 else 485 { 486 m_Edit9 += str_show; 487 } 488 } 489 CComboBox* pct = (CComboBox *)this->GetDlgItem(IDC_COMBO1); 490 if (pct->GetCurSel() == 2) 491 { 492 m_Edit9 += "315MHz"; 493 } 494 else if (pct->GetCurSel() == 1) 495 { 496 m_Edit9 += "433MHz"; 497 } 498 else if (pct->GetCurSel() == 0) 499 { 500 m_Edit9 += "Scaner"; 501 } 502 else 503 { 504 m_Edit9 += "Scaner"; 505 } 506 } 507 } 508 UpdateData(false); 509 SetCurrentDirectory(chCurDir); 510 ::FreeLibrary(hModule); 511 } 512 513 void CFobsignupDlg::Clear_BN_CLICKED() 514 { 515 // TODO: Add your control notification handler code here 516 m_Edit2 = m_Edit3 = m_Edit4 = m_Edit5 = m_Edit6 = m_Edit7 = m_Edit8 = m_Edit9 = ""; 517 UpdateData(false); 518 } 519 BEGIN_EVENTSINK_MAP(CFobsignupDlg, CDialogEx) 520 ON_EVENT(CFobsignupDlg, IDC_MSCOMM1, 1, CFobsignupDlg::OnCommMscomm1, VTS_NONE) 521 END_EVENTSINK_MAP() 522 523 524 void CFobsignupDlg::OnCommMscomm1() 525 { 526 // TODO: Add your message handler code here 527 long len, i; 528 BYTE rxdata[64]; //rx buffer 529 VARIANT variant_inp; 530 COleSafeArray safearray_inp; 531 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK1); 532 CMscomm1 *pcom = (CMscomm1*)this->GetDlgItem(IDC_MSCOMM1); 533 if (pcom->get_CommEvent() == 2) 534 { 535 variant_inp = pcom->get_Input(); //read rx buffer 536 safearray_inp = variant_inp; //VARIANT to COleSafeArray calss 537 len = safearray_inp.GetOneDimSize(); //get the active length of data byte 538 if (len != 30) 539 return; 540 if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED) 541 { 542 pt->SetCheck(false); 543 } 544 m_Edit1 = ""; 545 for (i = 0; i<(len - 2); i++) //ignore ' ' symbol 546 { 547 safearray_inp.GetElement(&i, rxdata + i); 548 if ((i+1)%5 == 0); //ignore space symbols 549 else 550 { 551 m_Edit1 += rxdata[i]; 552 } 553 } 554 UpdateData(false); 555 } 556 } 557 558 559 void CFobsignupDlg::write_BN_CLICKED() 560 { 561 // TODO: Add your control notification handler code here 562 CMscomm1 *pcomm = (CMscomm1 *)this->GetDlgItem(IDC_MSCOMM1); 563 if (pcomm->get_PortOpen()==false) 564 { 565 MessageBox("Serial Port DID NOT Open."); 566 } 567 else if (m_Edit9 == "") 568 { 569 MessageBox("No message Write."); 570 } 571 else 572 { 573 pcomm->put_Output(COleVariant(m_Edit9)); 574 } 575 } 576 577 578 void CFobsignupDlg::Open_Close_BN_CLICKED() 579 { 580 // TODO: Add your control notification handler code here 581 CMscomm1 *pcm = (CMscomm1 *)this ->GetDlgItem(IDC_MSCOMM1); 582 CComboBox* pFreq = (CComboBox *)this->GetDlgItem(IDC_COMBO1); 583 CComboBox* pport = (CComboBox *)this->GetDlgItem(IDC_COMBO2); 584 CComboBox* pbaud = (CComboBox *)this->GetDlgItem(IDC_COMBO3); 585 if (pcm->get_PortOpen() == false) 586 { 587 pcm->put_CommPort(pport->GetCurSel()); 588 if (pbaud->GetCurSel() == 0) 589 { 590 pcm->put_Settings("2400,n,8,1"); 591 } 592 else if (pbaud->GetCurSel() == 1) 593 { 594 pcm->put_Settings("4800,n,8,1"); 595 } 596 else if (pbaud->GetCurSel() == 2) 597 { 598 pcm->put_Settings("9600,n,8,1"); 599 } 600 else if (pbaud->GetCurSel() == 3) 601 { 602 pcm->put_Settings("38400,n,8,1"); 603 } 604 else if (pbaud->GetCurSel() == 4) 605 { 606 pcm->put_Settings("115200,n,8,1"); 607 } 608 else 609 { 610 pcm->put_Settings("9600,n,8,1"); 611 } 612 pcm->put_InputMode(1); //1: read data by binary checking 613 pcm->put_RThreshold(30); //onComm event trigger when N byte in input buffer 614 pcm->put_InputLen(0); //set input length 0. 615 pcm->put_PortOpen(true); 616 } 617 else 618 { 619 pcm->put_PortOpen(false); 620 } 621 if (pcm->get_PortOpen() == false) 622 { 623 SetDlgItemTextA(IDC_BUTTON4, "Open"); 624 pport->EnableWindow(true); 625 pbaud->EnableWindow(true); 626 pFreq->EnableWindow(true); 627 } 628 else 629 { 630 SetDlgItemTextA(IDC_BUTTON4, "Close"); 631 pport->EnableWindow(false); 632 pbaud->EnableWindow(false); 633 pFreq->EnableWindow(false); 634 } 635 } 636 637 638 void CFobsignupDlg::checkBox1_BN_CLICKED() 639 { 640 // TODO: Add your control notification handler code here 641 char buf[50]; 642 int i, k; 643 unsigned char fob_buf[16]; 644 CString str; 645 CString str_show(fob_buf); 646 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK1); 647 //get context from edit1 648 UpdateData(true); 649 GetDlgItem(IDC_EDIT1)->GetWindowText(str); 650 if (IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED) 651 { 652 if (str.GetLength() == 0) 653 { 654 pt->SetCheck(false); 655 AfxMessageBox("zero length"); 656 return; 657 } 658 } 659 else if (str.GetLength() == 0) 660 { 661 return; 662 } 663 strcpy(buf, str); 664 TCHAR chCurDir[MAX_PATH] = { 0 }; 665 GetCurrentDirectory(MAX_PATH, chCurDir); 666 SetCurrentDirectory(_T("C:\Windows")); 667 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 668 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 669 if (!ToChar(buf, fob_buf, 24)) 670 { 671 pt->SetCheck(false); 672 AfxMessageBox("data invalid."); 673 } 674 else 675 { 676 fob_buf[12] = 0; 677 fob_buf[13] = 0; 678 fob_buf[14] = 0; 679 fob_buf[15] = 0; 680 m_Edit1 = ""; 681 for (i = 0; i < 12; i++) 682 { 683 str_show.Format("%X", fob_buf[11 - i]); 684 k = strlen(str_show); 685 if (k == 0) 686 { 687 m_Edit1 = "00"; 688 } 689 else if (k == 1) 690 { 691 m_Edit1 += "0"; 692 m_Edit1 += str_show; 693 } 694 else 695 { 696 m_Edit1 += str_show; 697 } 698 } 699 } 700 UpdateData(false); 701 SetCurrentDirectory(chCurDir); 702 ::FreeLibrary(hModule); 703 } 704 705 706 void CFobsignupDlg::checkBox2_BN_CLICKED() 707 { 708 // TODO: Add your control notification handler code here 709 char buf[96]; 710 int i, k; 711 unsigned char fob_buf[16]; 712 CString str; 713 CString str_show(fob_buf); 714 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK2); 715 //get context from edit1 716 UpdateData(true); 717 GetDlgItem(IDC_EDIT2)->GetWindowText(str); 718 if (IsDlgButtonChecked(IDC_CHECK2) == BST_CHECKED) 719 { 720 if (str.GetLength() == 0) 721 { 722 pt->SetCheck(false); 723 AfxMessageBox("zero length"); 724 return; 725 } 726 } 727 else if (str.GetLength() == 0) 728 { 729 return; 730 } 731 strcpy(buf, str); 732 TCHAR chCurDir[MAX_PATH] = { 0 }; 733 GetCurrentDirectory(MAX_PATH, chCurDir); 734 SetCurrentDirectory(_T("C:\Windows")); 735 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 736 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 737 if (!ToChar(buf, fob_buf, 32)) 738 { 739 pt->SetCheck(false); 740 AfxMessageBox("data invalid."); 741 } 742 else 743 { 744 m_Edit2 = ""; 745 for (i = 0; i < 16; i++) 746 { 747 str_show.Format("%X", fob_buf[15 - i]); 748 k = strlen(str_show); 749 if (k == 0) 750 { 751 m_Edit2 = "00"; 752 } 753 else if (k == 1) 754 { 755 m_Edit2 += "0"; 756 m_Edit2 += str_show; 757 } 758 else 759 { 760 m_Edit2 += str_show; 761 } 762 } 763 } 764 UpdateData(false); 765 SetCurrentDirectory(chCurDir); 766 ::FreeLibrary(hModule); 767 } 768 769 770 void CFobsignupDlg::checkBox3_BN_CLICKED() 771 { 772 // TODO: Add your control notification handler code here 773 char buf[96]; 774 int i, k; 775 unsigned char fob_buf[16]; 776 CString str; 777 CString str_show(fob_buf); 778 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK3); 779 //get context from edit1 780 UpdateData(true); 781 GetDlgItem(IDC_EDIT3)->GetWindowText(str); 782 if (IsDlgButtonChecked(IDC_CHECK3) == BST_CHECKED) 783 { 784 if (str.GetLength() == 0) 785 { 786 pt->SetCheck(false); 787 AfxMessageBox("zero length"); 788 return; 789 } 790 } 791 else if (str.GetLength() == 0) 792 { 793 return; 794 } 795 strcpy(buf, str); 796 TCHAR chCurDir[MAX_PATH] = { 0 }; 797 GetCurrentDirectory(MAX_PATH, chCurDir); 798 SetCurrentDirectory(_T("C:\Windows")); 799 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 800 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 801 if (!ToChar(buf, fob_buf, 32)) 802 { 803 pt->SetCheck(false); 804 AfxMessageBox("data invalid."); 805 } 806 else 807 { 808 m_Edit3 = ""; 809 for (i = 0; i < 16; i++) 810 { 811 str_show.Format("%X", fob_buf[15 - i]); 812 k = strlen(str_show); 813 if (k == 0) 814 { 815 m_Edit3 = "00"; 816 } 817 else if (k == 1) 818 { 819 m_Edit3 += "0"; 820 m_Edit3 += str_show; 821 } 822 else 823 { 824 m_Edit3 += str_show; 825 } 826 } 827 } 828 UpdateData(false); 829 SetCurrentDirectory(chCurDir); 830 ::FreeLibrary(hModule); 831 } 832 833 834 void CFobsignupDlg::checkBox4_BN_CLICKED() 835 { 836 // TODO: Add your control notification handler code here 837 char buf[96]; 838 int i, k; 839 unsigned char fob_buf[16]; 840 CString str; 841 CString str_show(fob_buf); 842 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK4); 843 //get context from edit1 844 UpdateData(true); 845 GetDlgItem(IDC_EDIT4)->GetWindowText(str); 846 if (IsDlgButtonChecked(IDC_CHECK4) == BST_CHECKED) 847 { 848 if (str.GetLength() == 0) 849 { 850 pt->SetCheck(false); 851 AfxMessageBox("zero length"); 852 return; 853 } 854 } 855 else if (str.GetLength() == 0) 856 { 857 return; 858 } 859 strcpy(buf, str); 860 TCHAR chCurDir[MAX_PATH] = { 0 }; 861 GetCurrentDirectory(MAX_PATH, chCurDir); 862 SetCurrentDirectory(_T("C:\Windows")); 863 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 864 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 865 if (!ToChar(buf, fob_buf, 32)) 866 { 867 pt->SetCheck(false); 868 AfxMessageBox("data invalid."); 869 } 870 else 871 { 872 m_Edit4 = ""; 873 for (i = 0; i < 16; i++) 874 { 875 str_show.Format("%X", fob_buf[15 - i]); 876 k = strlen(str_show); 877 if (k == 0) 878 { 879 m_Edit4 = "00"; 880 } 881 else if (k == 1) 882 { 883 m_Edit4 += "0"; 884 m_Edit4 += str_show; 885 } 886 else 887 { 888 m_Edit4 += str_show; 889 } 890 } 891 } 892 UpdateData(false); 893 SetCurrentDirectory(chCurDir); 894 ::FreeLibrary(hModule); 895 } 896 897 898 void CFobsignupDlg::checkBox5_BN_CLICKED() 899 { 900 // TODO: Add your control notification handler code here 901 char buf[96]; 902 int i, k; 903 unsigned char fob_buf[16]; 904 CString str; 905 CString str_show(fob_buf); 906 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK5); 907 //get context from edit1 908 UpdateData(true); 909 GetDlgItem(IDC_EDIT5)->GetWindowText(str); 910 if (IsDlgButtonChecked(IDC_CHECK5) == BST_CHECKED) 911 { 912 if (str.GetLength() == 0) 913 { 914 pt->SetCheck(false); 915 AfxMessageBox("zero length"); 916 return; 917 } 918 } 919 else if (str.GetLength() == 0) 920 { 921 return; 922 } 923 strcpy(buf, str); 924 TCHAR chCurDir[MAX_PATH] = { 0 }; 925 GetCurrentDirectory(MAX_PATH, chCurDir); 926 SetCurrentDirectory(_T("C:\Windows")); 927 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 928 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 929 if (!ToChar(buf, fob_buf, 32)) 930 { 931 pt->SetCheck(false); 932 AfxMessageBox("data invalid."); 933 } 934 else 935 { 936 m_Edit5 = ""; 937 for (i = 0; i < 16; i++) 938 { 939 str_show.Format("%X", fob_buf[15 - i]); 940 k = strlen(str_show); 941 if (k == 0) 942 { 943 m_Edit5 = "00"; 944 } 945 else if (k == 1) 946 { 947 m_Edit5 += "0"; 948 m_Edit5 += str_show; 949 } 950 else 951 { 952 m_Edit5 += str_show; 953 } 954 } 955 } 956 UpdateData(false); 957 SetCurrentDirectory(chCurDir); 958 ::FreeLibrary(hModule); 959 } 960 961 962 void CFobsignupDlg::checkBox6_BN_CLICKED() 963 { 964 // TODO: Add your control notification handler code here 965 char buf[96]; 966 int i, k; 967 unsigned char fob_buf[16]; 968 CString str; 969 CString str_show(fob_buf); 970 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK6); 971 //get context from edit1 972 UpdateData(true); 973 GetDlgItem(IDC_EDIT6)->GetWindowText(str); 974 if (IsDlgButtonChecked(IDC_CHECK6) == BST_CHECKED) 975 { 976 if (str.GetLength() == 0) 977 { 978 pt->SetCheck(false); 979 AfxMessageBox("zero length"); 980 return; 981 } 982 } 983 else if (str.GetLength() == 0) 984 { 985 return; 986 } 987 strcpy(buf, str); 988 TCHAR chCurDir[MAX_PATH] = { 0 }; 989 GetCurrentDirectory(MAX_PATH, chCurDir); 990 SetCurrentDirectory(_T("C:\Windows")); 991 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 992 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 993 if (!ToChar(buf, fob_buf, 32)) 994 { 995 pt->SetCheck(false); 996 AfxMessageBox("data invalid."); 997 } 998 else 999 { 1000 m_Edit6 = ""; 1001 for (i = 0; i < 16; i++) 1002 { 1003 str_show.Format("%X", fob_buf[15 - i]); 1004 k = strlen(str_show); 1005 if (k == 0) 1006 { 1007 m_Edit6 = "00"; 1008 } 1009 else if (k == 1) 1010 { 1011 m_Edit6 += "0"; 1012 m_Edit6 += str_show; 1013 } 1014 else 1015 { 1016 m_Edit6 += str_show; 1017 } 1018 } 1019 } 1020 UpdateData(false); 1021 SetCurrentDirectory(chCurDir); 1022 ::FreeLibrary(hModule); 1023 } 1024 1025 1026 void CFobsignupDlg::checkBox7_BN_CLICKED() 1027 { 1028 // TODO: Add your control notification handler code here 1029 char buf[96]; 1030 int i, k; 1031 unsigned char fob_buf[16]; 1032 CString str; 1033 CString str_show(fob_buf); 1034 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK7); 1035 //get context from edit1 1036 UpdateData(true); 1037 GetDlgItem(IDC_EDIT7)->GetWindowText(str); 1038 if (IsDlgButtonChecked(IDC_CHECK7) == BST_CHECKED) 1039 { 1040 if (str.GetLength() == 0) 1041 { 1042 pt->SetCheck(false); 1043 AfxMessageBox("zero length"); 1044 return; 1045 } 1046 } 1047 else if (str.GetLength() == 0) 1048 { 1049 return; 1050 } 1051 strcpy(buf, str); 1052 TCHAR chCurDir[MAX_PATH] = { 0 }; 1053 GetCurrentDirectory(MAX_PATH, chCurDir); 1054 SetCurrentDirectory(_T("C:\Windows")); 1055 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 1056 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 1057 if (!ToChar(buf, fob_buf, 32)) 1058 { 1059 pt->SetCheck(false); 1060 AfxMessageBox("data invalid."); 1061 } 1062 else 1063 { 1064 m_Edit7 = ""; 1065 for (i = 0; i < 16; i++) 1066 { 1067 str_show.Format("%X", fob_buf[15 - i]); 1068 k = strlen(str_show); 1069 if (k == 0) 1070 { 1071 m_Edit7 = "00"; 1072 } 1073 else if (k == 1) 1074 { 1075 m_Edit7 += "0"; 1076 m_Edit7 += str_show; 1077 } 1078 else 1079 { 1080 m_Edit7 += str_show; 1081 } 1082 } 1083 } 1084 UpdateData(false); 1085 SetCurrentDirectory(chCurDir); 1086 ::FreeLibrary(hModule); 1087 } 1088 1089 1090 void CFobsignupDlg::checkBox8_BN_CLICKED() 1091 { 1092 // TODO: Add your control notification handler code here 1093 char buf[96]; 1094 int i, k; 1095 unsigned char fob_buf[16]; 1096 CString str; 1097 CString str_show(fob_buf); 1098 CButton*pt = (CButton*)GetDlgItem(IDC_CHECK8); 1099 //get context from edit1 1100 UpdateData(true); 1101 GetDlgItem(IDC_EDIT8)->GetWindowText(str); 1102 if (IsDlgButtonChecked(IDC_CHECK8) == BST_CHECKED) 1103 { 1104 if (str.GetLength() == 0) 1105 { 1106 pt->SetCheck(false); 1107 AfxMessageBox("zero length"); 1108 return; 1109 } 1110 } 1111 else if (str.GetLength() == 0) 1112 { 1113 return; 1114 } 1115 strcpy(buf, str); 1116 TCHAR chCurDir[MAX_PATH] = { 0 }; 1117 GetCurrentDirectory(MAX_PATH, chCurDir); 1118 SetCurrentDirectory(_T("C:\Windows")); 1119 HMODULE hModule = ::LoadLibrary(_T("AES_DLL.dll")); 1120 C2HFUN ToChar = (C2HFUN)::GetProcAddress(hModule, "char_to_hex"); 1121 if (!ToChar(buf, fob_buf, 32)) 1122 { 1123 pt->SetCheck(false); 1124 AfxMessageBox("data invalid."); 1125 } 1126 else 1127 { 1128 m_Edit8 = ""; 1129 for (i = 0; i < 16; i++) 1130 { 1131 str_show.Format("%X", fob_buf[15 - i]); 1132 k = strlen(str_show); 1133 if (k == 0) 1134 { 1135 m_Edit8 = "00"; 1136 } 1137 else if (k == 1) 1138 { 1139 m_Edit8 += "0"; 1140 m_Edit8 += str_show; 1141 } 1142 else 1143 { 1144 m_Edit8 += str_show; 1145 } 1146 } 1147 } 1148 UpdateData(false); 1149 SetCurrentDirectory(chCurDir); 1150 ::FreeLibrary(hModule); 1151 }
Thanks,
End.