home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / zkuste / vbasic / Data / Utils / XZipComp.exe / XceedEncryption.Cab / F112949_unOptions.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-07-03  |  4.5 KB  |  143 lines

  1. {
  2.   Xceed Encryption Library - Memory Encryption Sample
  3.   Copyright (c) 2001 Xceed Software Inc
  4.  
  5.   [unOptions.pas]
  6.  
  7.   This unit displays available encryption options
  8.  
  9.   This file is part of the Xceed Encryption Library sample applications.
  10.   The source code in this file is only intended as a supplment to the Xceed
  11.   Encryption Library's documentation and is provided "as is", without warranty
  12.   of any kind either expressed or implied.
  13. }
  14.  
  15. unit unOptions;
  16.  
  17. interface
  18.  
  19. uses
  20.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  21.   StdCtrls, unMemEncrypt, XceedEncryptionLib_TLB;
  22.  
  23. type
  24.   TfrmOptions = class(TForm)
  25.     Label1              : TLabel;
  26.     Label2              : TLabel;
  27.     Label3              : TLabel;
  28.     Label4              : TLabel;
  29.     Label5              : TLabel;
  30.     cboEncryptionMethod : TComboBox;
  31.     cboEncryptionMode   : TComboBox;
  32.     cboKeySize          : TComboBox;
  33.     cboHashingMethod    : TComboBox;
  34.     cboPaddingMethod    : TComboBox;
  35.     btOk                : TButton;
  36.     btCancel            : TButton;
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure FormDestroy(Sender: TObject);
  39.     procedure btCancelClick(Sender: TObject);
  40.     procedure btOkClick(Sender: TObject);
  41.   private
  42.     m_bOK : boolean;
  43.  
  44.   public
  45.  
  46.     function ShowForm( var eEncryptionMethod : TEncryptionMethod;
  47.                        var eEncryptionMode   : EXEEncryptionMode;
  48.                        var ePaddingMethod    : EXEPaddingMethod;
  49.                        var eHashingMethod    : THashingMethod;
  50.                        var lKeySize          : integer ) : boolean;
  51.   end;
  52.  
  53. var
  54.   frmOptions: TfrmOptions;
  55.  
  56. implementation
  57.  
  58. {$R *.DFM}
  59.  
  60. {***************************************************************}
  61. {                                                               }
  62. { FORM EVENTS                                                   }
  63. {                                                               }
  64. {***************************************************************}
  65.  
  66. {---------------------------------------------------------------}
  67. procedure TfrmOptions.FormCreate(Sender: TObject);
  68. begin
  69.   cboEncryptionMethod.ItemIndex := 0;
  70.   cboEncryptionMode.ItemIndex   := 0;
  71.   cboKeySize.ItemIndex          := 0;
  72.   cboHashingMethod.ItemIndex    := 0;
  73.   cboPaddingMethod.ItemIndex    := 0; 
  74.   m_bOk := false;
  75. end;
  76.  
  77. {---------------------------------------------------------------}
  78. procedure TfrmOptions.FormDestroy(Sender: TObject);
  79. begin
  80.   btCancel.Click();
  81. end;
  82.  
  83. {---------------------------------------------------------------}
  84. procedure TfrmOptions.btCancelClick(Sender: TObject);
  85. begin
  86.   Self.ModalResult := 1;
  87.   Self.Hide();
  88. end;
  89.  
  90. {---------------------------------------------------------------}
  91. procedure TfrmOptions.btOkClick(Sender: TObject);
  92. begin
  93.   m_bOk := true;
  94.   Self.ModalResult := 1;
  95.   Self.Hide();
  96. end;
  97.  
  98. {***************************************************************}
  99. {                                                               }
  100. { FORM FUNCTIONS AND PROCEDURES                                 }
  101. {                                                               }
  102. {***************************************************************}
  103.  
  104. {---------------------------------------------------------------}
  105. function TfrmOptions.ShowForm( var eEncryptionMethod : TEncryptionMethod;
  106.                                var eEncryptionMode   : EXEEncryptionMode;
  107.                                var ePaddingMethod    : EXEPaddingMethod;
  108.                                var eHashingMethod    : THashingMethod;
  109.                                var lKeySize          : integer ) : boolean;
  110. begin
  111.  
  112.   cboEncryptionMethod.ItemIndex := Ord( eEncryptionMethod );
  113.   cboEncryptionMode.ItemIndex := Ord( eEncryptionMode );
  114.   cboPaddingMethod.ItemIndex := Ord( ePaddingMethod );
  115.   cboHashingMethod.ItemIndex := Ord( eHashingMethod );
  116.  
  117.   case lKeySize of
  118.     128 : cboKeySize.ItemIndex := 0;
  119.     192 : cboKeySize.ItemIndex := 1;
  120.     256 : cboKeySize.ItemIndex := 2;
  121.   end;
  122.  
  123.   Self.ShowModal();
  124.  
  125.   if m_bOK then
  126.   begin
  127.     eEncryptionMethod := TEncryptionMethod( cboEncryptionMethod.ItemIndex );
  128.     eEncryptionMode   := EXEEncryptionMode( cboEncryptionMode.ItemIndex );
  129.     ePaddingMethod    := EXEPaddingMethod ( cboPaddingMethod.ItemIndex );
  130.     eHashingMethod    := THashingMethod   ( cboHashingMethod.ItemIndex );
  131.  
  132.     case cboKeySize.ItemIndex of
  133.       0 : lKeySize := 128;
  134.       1 : lKeySize := 192;
  135.       2 : lKeySize := 256;
  136.     end;
  137.   end;
  138.   ShowForm := m_bOk;
  139.   Self.Close();
  140. end;
  141.  
  142. end.
  143.