home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncryption.Cab / F113019_OptionDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  4.8 KB  |  144 lines

  1. // Xceed Encryption Library - Memory Encrypt sample
  2. // Copyright (c) 2001 Xceed Software Inc.
  3. //
  4. // [OptionDlg.cpp]
  5. //
  6. // This form module displays properties for symmetric encryption.
  7. //
  8. // This file is part of the Xceed Encryption Library sample applications.
  9. // The source code in this file is only intended as a supplement to Xceed
  10. // Encryption Library's documentation, and is provided "as is", without
  11. // warranty of any kind, either expressed or implied.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "memoryencrypt.h"
  16. #include "OptionDlg.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // COptionDlg dialog
  26.  
  27.  
  28. COptionDlg::COptionDlg(CWnd* pParent /*=NULL*/)
  29.     : CDialog(COptionDlg::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(COptionDlg)
  32.     m_nEncryptionMethod = -1;
  33.     m_nEncryptionMode = -1;
  34.     m_nHashingMethod = -1;
  35.     m_nKeySize = -1;
  36.     m_nPaddingMethod = -1;
  37.     //}}AFX_DATA_INIT
  38. }
  39.  
  40.  
  41. void COptionDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43.     CDialog::DoDataExchange(pDX);
  44.     //{{AFX_DATA_MAP(COptionDlg)
  45.     DDX_Control(pDX, IDC_CBO_PADDINGMETHOD, m_cboPaddingMethod);
  46.     DDX_Control(pDX, IDC_CBO_KEYSIZE, m_cboKeySize);
  47.     DDX_Control(pDX, IDC_CBO_HASHINGMETHOD, m_cboHashingMethod);
  48.     DDX_Control(pDX, IDC_CBO_ENCRYPTIONMODE, m_cboEncryptionMode);
  49.     DDX_Control(pDX, IDC_CBO_ENCRYPTIONMETHOD, m_cboEncryptionMethod);
  50.     DDX_CBIndex(pDX, IDC_CBO_ENCRYPTIONMETHOD, m_nEncryptionMethod);
  51.     DDX_CBIndex(pDX, IDC_CBO_ENCRYPTIONMODE, m_nEncryptionMode);
  52.     DDX_CBIndex(pDX, IDC_CBO_HASHINGMETHOD, m_nHashingMethod);
  53.     DDX_CBIndex(pDX, IDC_CBO_KEYSIZE, m_nKeySize);
  54.     DDX_CBIndex(pDX, IDC_CBO_PADDINGMETHOD, m_nPaddingMethod);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP(COptionDlg, CDialog)
  59.     //{{AFX_MSG_MAP(COptionDlg)
  60.     //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62.  
  63.  
  64. //------------------------------------------------------------------------------------
  65. // Display the option form with the combo boxes set to the right value according
  66. // to the parameters. Update the parameter values if the user clicked OK.
  67. //------------------------------------------------------------------------------------
  68. bool COptionDlg::ShowForm( enuEncryptionMethod* eEncryptionMethod,
  69.                            enuEncryptionMode* eEncryptionMode,
  70.                            enuHashingMethod* eHashingMethod,
  71.                            short* nKeySize,
  72.                            enuPaddingMethod* ePaddingMethod )
  73. {
  74.   m_nEncryptionMethod = *eEncryptionMethod;
  75.   m_nEncryptionMode = *eEncryptionMode;
  76.   m_nHashingMethod = *eHashingMethod;
  77.   m_nKeySize = *nKeySize;
  78.   m_nPaddingMethod = *ePaddingMethod;
  79.  
  80.   if( DoModal() == IDOK )
  81.   {
  82.     *eEncryptionMethod = ( enuEncryptionMethod )m_nEncryptionMethod;
  83.     *eEncryptionMode = ( enuEncryptionMode )m_nEncryptionMode;
  84.     *eHashingMethod = ( enuHashingMethod )m_nHashingMethod;
  85.     *nKeySize = m_nKeySize;
  86.     *ePaddingMethod = ( enuPaddingMethod )m_nPaddingMethod;
  87.  
  88.     return true;
  89.   }
  90.   else
  91.     return false;
  92. }
  93.  
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // COptionDlg message handlers
  97.  
  98. BOOL COptionDlg::OnInitDialog() 
  99. {
  100.     CDialog::OnInitDialog();
  101.  
  102.   // Fill the combo boxes
  103.   m_cboEncryptionMethod.AddString( "Rijndael" );
  104.   m_cboEncryptionMethod.AddString( "Twofish" );
  105.   m_cboEncryptionMethod.SetCurSel( m_nEncryptionMethod );
  106.  
  107.   m_cboEncryptionMode.AddString( "Free blocks (ECB)" );
  108.   m_cboEncryptionMode.AddString( "Chained blocks (CBC)" );
  109.   m_cboEncryptionMode.SetCurSel( m_nEncryptionMode );
  110.  
  111.   m_cboHashingMethod.AddString( "Haval" );
  112.   m_cboHashingMethod.AddString( "SHA" );
  113.   m_cboHashingMethod.SetCurSel( m_nHashingMethod );
  114.  
  115.   m_cboKeySize.SetItemData( m_cboKeySize.AddString( "128 bits" ), 128 );
  116.   m_cboKeySize.SetItemData( m_cboKeySize.AddString( "192 bits" ), 192 );
  117.   m_cboKeySize.SetItemData( m_cboKeySize.AddString( "256 bits" ), 256 );
  118.   // Transform the key size (in bits) received to the corresponding
  119.   // index in the combo box.
  120.   for( int i = 0; i < m_cboKeySize.GetCount(); i++ )
  121.   {
  122.     if( m_cboKeySize.GetItemData( i ) == static_cast<DWORD>( m_nKeySize ) )
  123.       m_nKeySize = i;
  124.   }
  125.   m_cboKeySize.SetCurSel( m_nKeySize );
  126.  
  127.   m_cboPaddingMethod.AddString( "FIPS 81" );
  128.   m_cboPaddingMethod.AddString( "Random" );
  129.   m_cboPaddingMethod.AddString( "RFC-1423" );
  130.   m_cboPaddingMethod.SetCurSel( m_nPaddingMethod );
  131.  
  132.     return TRUE;  // return TRUE unless you set the focus to a control
  133.                   // EXCEPTION: OCX Property Pages should return FALSE
  134. }
  135.  
  136. void COptionDlg::OnOK() 
  137. {
  138.     CDialog::OnOK();
  139.  
  140.   // Transform the key size combo index value to its corresponding
  141.   // key size value in bits.
  142.   m_nKeySize = static_cast<short>( m_cboKeySize.GetItemData( m_nKeySize ) );
  143. }
  144.