home *** CD-ROM | disk | FTP | other *** search
- // Xceed Encryption Library - Memory Encrypt sample
- // Copyright (c) 2001 Xceed Software Inc.
- //
- // [OptionDlg.cpp]
- //
- // This form module displays properties for symmetric encryption.
- //
- // This file is part of the Xceed Encryption Library sample applications.
- // The source code in this file is only intended as a supplement to Xceed
- // Encryption Library's documentation, and is provided "as is", without
- // warranty of any kind, either expressed or implied.
-
-
- #include "stdafx.h"
- #include "memoryencrypt.h"
- #include "OptionDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // COptionDlg dialog
-
-
- COptionDlg::COptionDlg(CWnd* pParent /*=NULL*/)
- : CDialog(COptionDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(COptionDlg)
- m_nEncryptionMethod = -1;
- m_nEncryptionMode = -1;
- m_nHashingMethod = -1;
- m_nKeySize = -1;
- m_nPaddingMethod = -1;
- //}}AFX_DATA_INIT
- }
-
-
- void COptionDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(COptionDlg)
- DDX_Control(pDX, IDC_CBO_PADDINGMETHOD, m_cboPaddingMethod);
- DDX_Control(pDX, IDC_CBO_KEYSIZE, m_cboKeySize);
- DDX_Control(pDX, IDC_CBO_HASHINGMETHOD, m_cboHashingMethod);
- DDX_Control(pDX, IDC_CBO_ENCRYPTIONMODE, m_cboEncryptionMode);
- DDX_Control(pDX, IDC_CBO_ENCRYPTIONMETHOD, m_cboEncryptionMethod);
- DDX_CBIndex(pDX, IDC_CBO_ENCRYPTIONMETHOD, m_nEncryptionMethod);
- DDX_CBIndex(pDX, IDC_CBO_ENCRYPTIONMODE, m_nEncryptionMode);
- DDX_CBIndex(pDX, IDC_CBO_HASHINGMETHOD, m_nHashingMethod);
- DDX_CBIndex(pDX, IDC_CBO_KEYSIZE, m_nKeySize);
- DDX_CBIndex(pDX, IDC_CBO_PADDINGMETHOD, m_nPaddingMethod);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(COptionDlg, CDialog)
- //{{AFX_MSG_MAP(COptionDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- //------------------------------------------------------------------------------------
- // Display the option form with the combo boxes set to the right value according
- // to the parameters. Update the parameter values if the user clicked OK.
- //------------------------------------------------------------------------------------
- bool COptionDlg::ShowForm( enuEncryptionMethod* eEncryptionMethod,
- enuEncryptionMode* eEncryptionMode,
- enuHashingMethod* eHashingMethod,
- short* nKeySize,
- enuPaddingMethod* ePaddingMethod )
- {
- m_nEncryptionMethod = *eEncryptionMethod;
- m_nEncryptionMode = *eEncryptionMode;
- m_nHashingMethod = *eHashingMethod;
- m_nKeySize = *nKeySize;
- m_nPaddingMethod = *ePaddingMethod;
-
- if( DoModal() == IDOK )
- {
- *eEncryptionMethod = ( enuEncryptionMethod )m_nEncryptionMethod;
- *eEncryptionMode = ( enuEncryptionMode )m_nEncryptionMode;
- *eHashingMethod = ( enuHashingMethod )m_nHashingMethod;
- *nKeySize = m_nKeySize;
- *ePaddingMethod = ( enuPaddingMethod )m_nPaddingMethod;
-
- return true;
- }
- else
- return false;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // COptionDlg message handlers
-
- BOOL COptionDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Fill the combo boxes
- m_cboEncryptionMethod.AddString( "Rijndael" );
- m_cboEncryptionMethod.AddString( "Twofish" );
- m_cboEncryptionMethod.SetCurSel( m_nEncryptionMethod );
-
- m_cboEncryptionMode.AddString( "Free blocks (ECB)" );
- m_cboEncryptionMode.AddString( "Chained blocks (CBC)" );
- m_cboEncryptionMode.SetCurSel( m_nEncryptionMode );
-
- m_cboHashingMethod.AddString( "Haval" );
- m_cboHashingMethod.AddString( "SHA" );
- m_cboHashingMethod.SetCurSel( m_nHashingMethod );
-
- m_cboKeySize.SetItemData( m_cboKeySize.AddString( "128 bits" ), 128 );
- m_cboKeySize.SetItemData( m_cboKeySize.AddString( "192 bits" ), 192 );
- m_cboKeySize.SetItemData( m_cboKeySize.AddString( "256 bits" ), 256 );
- // Transform the key size (in bits) received to the corresponding
- // index in the combo box.
- for( int i = 0; i < m_cboKeySize.GetCount(); i++ )
- {
- if( m_cboKeySize.GetItemData( i ) == static_cast<DWORD>( m_nKeySize ) )
- m_nKeySize = i;
- }
- m_cboKeySize.SetCurSel( m_nKeySize );
-
- m_cboPaddingMethod.AddString( "FIPS 81" );
- m_cboPaddingMethod.AddString( "Random" );
- m_cboPaddingMethod.AddString( "RFC-1423" );
- m_cboPaddingMethod.SetCurSel( m_nPaddingMethod );
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
-
- void COptionDlg::OnOK()
- {
- CDialog::OnOK();
-
- // Transform the key size combo index value to its corresponding
- // key size value in bits.
- m_nKeySize = static_cast<short>( m_cboKeySize.GetItemData( m_nKeySize ) );
- }
-