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

  1. {
  2.   Xceed Encryption Library - Memory Encryption Sample
  3.   Copyright (c) 2001 Xceed Software Inc
  4.  
  5.   [unMemEncrypt.pas]
  6.  
  7.   This unit contains the main form's code. It demonstrates how to
  8.   Encrypt a chunk of memory data using different kinds of Encryption methods,
  9.   and how to decrypt encrypted memory data. It specifically uses:
  10.     - The Encrypt, Decrypt, SetSecretKeyFromPassPhrase,
  11.       SetRandomInitVector and SetRandomKeyPair methods.
  12.     - The HasdhingMethod, HashSize, EncryptionMode, PaddingMethod,
  13.       EncryptionMethod, PrivateKey and PublicKey properties.
  14.  
  15.   This file is part of the Xceed Encryption Library sample applications.
  16.   The source code in this file is only intended as a supplment to the Xceed
  17.   Encryption Library's documentation and is provided "as is", without warranty
  18.   of any kind either expressed or implied.
  19. }
  20.  
  21. unit unMemEncrypt;
  22.  
  23. interface
  24.  
  25. uses
  26.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  27.   ExtCtrls, StdCtrls, XceedEncryptionLib_TLB;
  28.  
  29. //The different encryption methods
  30. type TEncryptionMethod = ( eemRijndael,   //0
  31.                            eemTwoFish );  //1
  32.  
  33. //The different hashing methods                           
  34. type THashingMethod = ( ehmSHA,          //0
  35.                         ehmHaval );      //1
  36.  
  37. type
  38.   TfrmMemoryEncrypt = class(TForm)
  39.     grpSymmetricEncryption  : TGroupBox;
  40.     grpAsymmetricEncryption : TGroupBox;
  41.     optSymmetricEncryption  : TRadioButton;
  42.     optAsymmetricEncryption : TRadioButton;
  43.     Label1                  : TLabel;
  44.     Label2                  : TLabel;
  45.     Label3                  : TLabel;
  46.     Label4                  : TLabel;
  47.     Label5                  : TLabel;
  48.     edtPassPhrase           : TEdit;
  49.     edtPrivateKeyFile       : TEdit;
  50.     edtPublicKeyFile        : TEdit;
  51.     btOptions               : TButton;
  52.     btSelectPrivateKeyFile  : TButton;
  53.     btSelectPublicKeyFile   : TButton;
  54.     btRandomKeyPair         : TButton;
  55.     btEncrypt               : TButton;
  56.     btDecrypt               : TButton;
  57.     mmoDecryptedText        : TMemo;
  58.     mmoEncryptedText        : TMemo;
  59.     xOpenDialog: TOpenDialog;
  60.     procedure FormCreate(Sender: TObject);
  61.     procedure btEncryptClick(Sender: TObject);
  62.     procedure btDecryptClick(Sender: TObject);
  63.     procedure btOptionsClick(Sender: TObject);
  64.     procedure btRandomKeyPairClick(Sender: TObject);
  65.     procedure btSelectPublicKeyFileClick(Sender: TObject);
  66.     procedure btSelectPrivateKeyFileClick(Sender: TObject);
  67.     procedure edtPrivateKeyFileExit(Sender: TObject);
  68.     procedure edtPublicKeyFileExit(Sender: TObject);
  69.     procedure optAsymmetricEncryptionClick(Sender: TObject);
  70.     procedure optSymmetricEncryptionClick(Sender: TObject);
  71.   private
  72.     //The values chosen by the user in the options form
  73.     m_eEncryptionMethod : TEncryptionMethod;
  74.     m_eEncryptionMode   : EXEEncryptionMode;
  75.     m_ePaddingMethod    : EXEPaddingMethod;
  76.     m_eHashingMethod    : THashingMethod;
  77.     m_lSecretKeySize    : integer;
  78.  
  79.     procedure EnableControls();
  80.     function PrepareEncryptionMethod( var xEncryptor : TXceedEncryption ) : boolean;
  81.     procedure ReadKeyFile( sKeyFile : string; var vaKey : OleVariant );
  82.     procedure SaveEncryptionType();
  83.     procedure SavePrivateKeyFileSetting();
  84.     procedure SavePublicKeyFileSetting();
  85.   public
  86.     { Public declarations }
  87.   end;
  88.  
  89. var
  90.   frmMemoryEncrypt: TfrmMemoryEncrypt;
  91.  
  92. implementation
  93.  
  94. uses unOptions, unKeyPair, unUtility, registry;
  95.  
  96. {$R *.DFM}
  97.  
  98. {***************************************************************}
  99. {                                                               }
  100. { FORM EVENTS                                                   }
  101. {                                                               }
  102. {***************************************************************}
  103.  
  104. {---------------------------------------------------------------}
  105. { Initialize the form and some of it's controls                 }
  106. {---------------------------------------------------------------}
  107. procedure TfrmMemoryEncrypt.FormCreate(Sender: TObject);
  108. var
  109.   xReg : TRegistryIniFile;
  110. begin
  111.   mmoDecryptedText.Text := 'This is a little test to show you how the memory ' +
  112.                            'encryption works. And is very easy to use.';
  113.  
  114.   //default value to avoid errors if the options are not set beforehand
  115.   xReg := TRegistryIniFile.Create( 'Software\Xceed\Delphi\MemEncrypt' );
  116.   m_eEncryptionMethod := TEncryptionMethod( xReg.ReadInteger( 'Encryption', 'EncryptionMethod', Ord( eemRijndael ) ) );
  117.   m_eEncryptionMode := xReg.ReadInteger( 'Encryption', 'EncryptionMode', emoFreeBlocks );
  118.   m_ePaddingMethod := xReg.ReadInteger( 'Encryption', 'PaddingMethod', epmFIPS81 );
  119.   m_eHashingMethod := THashingMethod( xReg.ReadInteger( 'Encryption', 'HashingMethod', Ord( ehmSHA ) ) );
  120.   m_lSecretKeySize := xReg.ReadInteger( 'Encryption', 'SecretKeySize', 128 );
  121.   edtPrivateKeyFile.Text := xReg.ReadString( 'Encryption', 'PrivateKeyfile', '' );
  122.   edtPublicKeyFile.Text := xReg.ReadString( 'Encryption', 'PublicKeyFile', '' );
  123.   optAsymmetricEncryption.Checked := xReg.ReadBool( 'Encryption', 'Asymmetric', false );
  124.   optSymmetricEncryption.Checked := xReg.ReadBool( 'Encryption', 'Symmetric', true );
  125.   xReg.Free();
  126.  
  127.   EnableControls();
  128. end;
  129.  
  130. {---------------------------------------------------------------}
  131. { Do the encryption of the original text                        }
  132. {---------------------------------------------------------------}
  133. procedure TfrmMemoryEncrypt.btEncryptClick(Sender: TObject);
  134. var
  135.   xEncryptor      : TXceedEncryption;
  136.   vaDecryptedText : OleVariant;
  137.   vaEncrypted     : OleVariant;
  138.   sHexEncrypted   : String;
  139. begin
  140.   try
  141.     //Create an instance of the Xceed Encryption control
  142.     xEncryptor := TXceedEncryption.Create( self );
  143.     vaDecryptedText := mmoDecryptedText.Text;
  144.  
  145.     //Create an prepare the Encryption Method
  146.     if( PrepareEncryptionMethod( xEncryptor ) ) then
  147.     begin
  148.       //Encrypt the string, specifying that (true parameter) this is the
  149.       //end of the data (there will be no more calls to Encrypt.
  150.       vaEncrypted := xEncryptor.Encrypt( vaDecryptedText, True );
  151.  
  152.       //Display the Encrypted result
  153.       //We convert the binary cipher text to an hexadecimal representation.
  154.       BinaryToHex( vaEncrypted, sHexEncrypted );
  155.  
  156.       // Display the result in the text box
  157.       mmoEncryptedText.Text := sHexEncrypted;
  158.     end;
  159.   except
  160.     on xErr : Exception do
  161.       ShowMessage( 'An error occurred during the encryption process! : ' +
  162.                    xErr.Message );
  163.   end;
  164.  
  165.   //Deallocate the Encryption object. The Encryption object will free the
  166.   //EncryptionMethod obeject
  167.   xEncryptor.Free();
  168. end;
  169.  
  170. {---------------------------------------------------------------}
  171. { Do the decryption of the encrypted text                       }
  172. {---------------------------------------------------------------}
  173. procedure TfrmMemoryEncrypt.btDecryptClick(Sender: TObject);
  174. var
  175.   xEncryptor      : TXceedEncryption;
  176.   vaEncryptedText : OleVariant;
  177.   vaDecrypted     : OleVariant;
  178. begin
  179.   try
  180.     //Create an instance of the Xceed Encryption Library
  181.     xEncryptor := TXceedEncryption.Create( self );
  182.  
  183.       //Create an prepare the Encryption Method
  184.       if( PrepareEncryptionMethod( xEncryptor ) ) then
  185.       begin
  186.         mmoDecryptedText.Clear();
  187.  
  188.         HexToBinary( mmoEncryptedText.Text, vaEncryptedText );
  189.  
  190.         //Decrypt the Encrypted string, specifying that (True parameter)
  191.         //this is the end of the data (there will be no more calls to Decrypt)
  192.  
  193.         vaDecrypted := xEncryptor.Decrypt( vaEncryptedText, True );
  194.  
  195.         if( VarIsEmpty( vaDecrypted ) ) then
  196.           //No output was produced
  197.           mmoDecryptedText.Text := ''
  198.         else
  199.         //Display the Decrypted result
  200.         mmoDecryptedText.Clear();
  201.         mmoDecryptedText.Text := vaDecrypted;
  202.       end;
  203.   except
  204.     on xErr : Exception do
  205.       ShowMessage( 'Error during Decryption process! : ' + xErr.Message );
  206.   end;
  207.   xEncryptor.Free();
  208. end;
  209.  
  210. {---------------------------------------------------------------}
  211. { Display the Options form, saving them if the user clicks OK   }
  212. {---------------------------------------------------------------}
  213. procedure TfrmMemoryEncrypt.btOptionsClick(Sender: TObject);
  214. var
  215.   xOptionsForm : TfrmOptions;
  216.   xReg : TRegistryIniFile;
  217. begin
  218.   xOptionsForm := TfrmOptions.Create( self );
  219.  
  220.   if xOptionsForm.ShowForm( m_eEncryptionMethod, m_eEncryptionMode,
  221.                          m_ePaddingMethod, m_eHashingMethod,
  222.                          m_lSecretKeySize ) then
  223.   begin
  224.     xReg := TRegistryIniFile.Create( 'Software\Xceed\Delphi\MemEncrypt' );
  225.     xReg.WriteInteger( 'Encryption', 'EncryptionMethod', Ord( m_eEncryptionMethod ) );
  226.     xReg.WriteInteger( 'Encryption', 'EncryptionMode', Ord( m_eEncryptionMode ) );
  227.     xReg.WriteInteger( 'Encryption', 'PaddingMethod', Ord( m_ePaddingMethod ) );
  228.     xReg.WriteInteger( 'Encryption', 'HashingMethod', Ord( m_eHashingMethod ) );
  229.     xReg.WriteInteger( 'Encryption', 'SecretKeySize', Ord( m_lSecretKeySize ) );
  230.     xReg.Free();
  231.   end;
  232.  
  233.   xOptionsForm.Free();
  234. end;
  235.  
  236. {---------------------------------------------------------------}
  237. { Generate new private and public keys stored in the file       }
  238. { specified in the respective edit boxes                        }
  239. {---------------------------------------------------------------}
  240. procedure TfrmMemoryEncrypt.btRandomKeyPairClick(Sender: TObject);
  241. var
  242.   xKeyPairForm : TfrmKeyPair;
  243. begin
  244.   //The file names are mandatory!!!!
  245.   if( length( trim( edtPrivateKeyFile.Text ) ) = 0 ) or ( length( trim( edtPublicKeyFile.Text ) ) = 0 ) then
  246.     ShowMessage( 'You must specify the key file names where the public and ' +
  247.                  'private keys will be stored!!' )
  248.   else
  249.   begin
  250.     //Show the dialog box used to generate a nre key pair, passing
  251.     //it the 2 file names.
  252.     xKeyPairForm := TfrmKeyPair.Create( self );
  253.     xKeyPairForm.ShowForm( edtPrivateKeyFile.Text, edtPublicKeyFile.Text );
  254.     xKeyPairForm.Free();
  255.   end;
  256. end;
  257.  
  258. {---------------------------------------------------------------}
  259. { Select the file name that contains (or will contain) the      }
  260. { private key                                                   }
  261. {---------------------------------------------------------------}
  262. procedure TfrmMemoryEncrypt.btSelectPrivateKeyFileClick(Sender: TObject);
  263. begin
  264.   xOpenDialog.Files.Clear();
  265.   xOpenDialog.Title := 'Source File';
  266.   xOpenDialog.Filter := 'Key File (*.key)|*.key|All Type (*.*)|*.*';
  267.   xOpenDialog.FilterIndex := 0;
  268.  
  269.   if( xOpenDialog.Execute ) then
  270.   begin
  271.     if( length( xOpenDialog.Files.Text ) > 0 )then
  272.       edtPrivateKeyFile.Text := trim( xOpenDialog.Files.Text );
  273.       SavePrivateKeyFileSetting();
  274.   end;
  275. end;
  276.  
  277. {---------------------------------------------------------------}
  278. { Select the file that contains (or will contain) the public key}
  279. {---------------------------------------------------------------}
  280. procedure TfrmMemoryEncrypt.btSelectPublicKeyFileClick(Sender: TObject);
  281. begin
  282.   xOpenDialog.Files.Clear();
  283.   xOpenDialog.Title := 'Source File';
  284.   xOpenDialog.Filter := 'Key File (*.key)|*.key|All Type (*.*)|*.*';
  285.   xOpenDialog.FilterIndex := 0;
  286.  
  287.   if( xOpenDialog.Execute ) then
  288.   begin
  289.     if( length( xOpenDialog.Files.Text ) > 0 ) then
  290.       edtPublicKeyFile.Text := trim( xOpenDialog.Files.Text );
  291.       SavePublicKeyFileSetting();
  292.   end;
  293. end;
  294.  
  295. {---------------------------------------------------------------}
  296. { The user exited the private key file text box. Save the       }
  297. { modification.                                                 }
  298. {---------------------------------------------------------------}
  299. procedure TfrmMemoryEncrypt.edtPrivateKeyFileExit(Sender: TObject);
  300. begin
  301.   SavePrivateKeyFileSetting();
  302. end;
  303.  
  304. {---------------------------------------------------------------}
  305. { The user exited the public key file text box. Save the        }
  306. { modification.                                                 }
  307. {---------------------------------------------------------------}
  308. procedure TfrmMemoryEncrypt.edtPublicKeyFileExit(Sender: TObject);
  309. begin
  310.   SavePublicKeyFileSetting();
  311. end;
  312.  
  313. {---------------------------------------------------------------}
  314. { The user selected asymmetric mode, disable controls           }
  315. { associated with symmetric encryption                          }
  316. {---------------------------------------------------------------}
  317. procedure TfrmMemoryEncrypt.optAsymmetricEncryptionClick(Sender: TObject);
  318. begin
  319.   if( self.visible ) then
  320.   begin
  321.     optSymmetricEncryption.Checked := false;
  322.     EnableControls();
  323.     SaveEncryptionType();
  324.   end;
  325. end;
  326.  
  327. {---------------------------------------------------------------}
  328. { The user selected symmetric mode, disable controls associated }
  329. { with asymmetric encryption.                                   }
  330. {---------------------------------------------------------------}
  331. procedure TfrmMemoryEncrypt.optSymmetricEncryptionClick(Sender: TObject);
  332. begin
  333.   if( self.Visible ) then
  334.   begin
  335.     optAsymmetricEncryption.Checked := false;
  336.     EnableControls();
  337.     SaveEncryptionType();
  338.   end;
  339. end;
  340.  
  341. {***************************************************************}
  342. {                                                               }
  343. { FORM FUNCTIONS AND PROCEDURES                                 }
  344. {                                                               }
  345. {***************************************************************}
  346.  
  347. {---------------------------------------------------------------}
  348. { Enable the control associated with the selected encryption    }
  349. { type (symmetric or asymmetric). Disable the other controls.   }
  350. {---------------------------------------------------------------}
  351. procedure TfrmMemoryEncrypt.EnableControls();
  352. var
  353.   bSecretKeyEncryption : boolean;
  354. begin
  355.   bSecretKeyEncryption := optSymmetricEncryption.Checked;
  356.  
  357.   edtPassPhrase.Enabled := bSecretKeyEncryption;
  358.   btOptions.Enabled := bSecretKeyEncryption;
  359.   edtPrivateKeyFile.Enabled := not bSecretKeyEncryption;
  360.   btSelectPrivateKeyFile.Enabled := not bSecretKeyEncryption;
  361.   edtPublicKeyFile.Enabled := not bSecretKeyEncryption;
  362.   btSelectPublicKeyFile.Enabled := not bSecretKeyEncryption;
  363.   btRandomKeyPair.Enabled := not bSecretKeyEncryption;
  364. end;
  365.  
  366. {---------------------------------------------------------------}
  367. { Prepare the encryption method according to the user selection }
  368. { Return true if all succeeded                                  }
  369. {---------------------------------------------------------------}
  370. function TfrmMemoryEncrypt.PrepareEncryptionMethod( var xEncryptor : TXceedEncryption ) : boolean;
  371.   //We use on variable for each encryption method to simplify the
  372.   //programming. Only one of these will be used at a time (according to the
  373.   //user selected Encryption Method.
  374. var
  375.   xRijndael    : DXceedRijndaelEncryptionMethod;
  376.   xTwoFish     : DXceedTwofishEncryptionMethod;
  377.   xRSA         : DXceedRSAEncryptionMethod;
  378.   xHaval       : DXceedHavalHashingMethod;
  379.   xSHA         : DXceedSHAHashingMethod;
  380.   vaPrivateKey : OleVariant;
  381.   vaPublicKey  : OleVariant;
  382.   bPrepareOk   : boolean;
  383. begin
  384.   bPrepareOk := true;
  385.   try
  386.     if optSymmetricEncryption.Checked then
  387.     begin
  388.       //the user chose to perform symmetric encryption/decryption
  389.  
  390.       case m_eEncryptionMethod of
  391.         eemRijndael : begin
  392.                         //Instantiate the Rijndael encryption method
  393.                         xRijndael := CoXceedRijndaelEncryptionMethod.Create();
  394.  
  395.                         //Set the hashing method that will be used to set the
  396.                         //key from the pass phrase
  397.                         case m_eHashingMethod of
  398.                           ehmHaval :  begin
  399.                                         xHaval := CoXceedHavalHashingMethod.Create();
  400.                                         //Haval supports hash sizes equivalent to the
  401.                                         //supported key size. So we can assign the latter
  402.                                         //to the former without problem.
  403.                                         xHaval.HashSize := m_lSecretKeySize;
  404.                                         xRijndael.HashingMethod := xHaval;
  405.                                       end;
  406.                           ehmSHA   :  begin
  407.                                         xSHA := CoXceedSHAHashingMethod.Create();
  408.  
  409.                                         //We arbitarily set the HashSize to the maximum
  410.                                         //key size allowed so we don't have to worry that
  411.                                         //the hash result of the pass phrase could be shorter
  412.                                         //than the expected key (although the Xceed Encryption
  413.                                         //Library would have dealt with it).
  414.                                         xSHA.HashSize := 256;
  415.                                         xRijndael.HashingMethod := xSHA;
  416.                                       end;
  417.                         end;
  418.  
  419.                         //Set the encryption mode
  420.                         xRijndael.EncryptionMode := m_eEncryptionMode;
  421.  
  422.                         //Set the padding method (for the last encrypted and decrypted block)
  423.                         xRijndael.PaddingMethod := m_ePaddingMethod;
  424.  
  425.                         //Set the secret key of the desired size using the user pass phrase
  426.                         xRijndael.SetSecretKeyFromPassPhrase( edtPassPhrase.Text, m_lSecretKeySize );
  427.  
  428.                         if ( m_eEncryptionMode = emoChainedBlocks ) then
  429.                           //Will be useful only when encryptin since, in decrption,
  430.                           //the InitVector is read at the beginning of the
  431.                           //encrypted text.
  432.                           xRijndael.SetRandomInitVector();
  433.  
  434.                         //Set the previously initialized encryption method
  435.                         //of the Encryptor object received as a parameter
  436.                         //of this function
  437.                         xEncryptor.EncryptionMethod := xRijndael;
  438.                       end;
  439.  
  440.         eemTwoFish :  begin
  441.                         //Intantiate the TwoFish encryption method
  442.                         xTwoFish := CoXceedTwofishEncryptionMethod.Create();
  443.  
  444.                         case m_eHashingMethod of
  445.                           ehmHaval :  begin
  446.                                         xHaval := CoXceedHavalHashingMethod.Create();
  447.                                         xHaval.HashSize := m_lSecretKeySize;
  448.                                         xTwoFish.HashingMethod := xHaval;
  449.                                       end;
  450.                           ehmSHA   :  begin
  451.                                         xSHA := CoXceedSHAHashingMethod.Create();
  452.                                         xSHA.HashSize := 256;
  453.                                         xTwoFish.HashingMethod := xSHA;
  454.                                       end;
  455.                         end;
  456.  
  457.                         xTwoFish.EncryptionMode := m_eEncryptionMode;
  458.                         xTwoFish.PaddingMethod := m_ePaddingMethod;
  459.                         xTwoFish.SetSecretKeyFromPassPhrase( edtPassPhrase.Text, m_lSecretKeySize );
  460.  
  461.                         if( m_eEncryptionMode = emoChainedBlocks ) then
  462.                           xTwoFish.SetRandomInitVector();
  463.  
  464.                         xEncryptor.EncryptionMethod := xTwoFish;
  465.                       end;
  466.       end;
  467.     end;
  468.  
  469.     //The user chose to perform asymmetric encryption/decryption
  470.     if optAsymmetricEncryption.Checked then
  471.     begin
  472.       //instantiate the RSA encryption method
  473.       xRSA := CoXceedRSAEncryptionMethod.Create();
  474.  
  475.       //Initialize the private key (used when decrypting)
  476.       ReadKeyFile( edtPrivateKeyFile.Text, vaPrivateKey );
  477.       xRSA.Set_PrivateKey( vaPrivateKey );
  478.  
  479.       //Initialize the public key (used when encrypting)
  480.       ReadKeyFile( edtPublicKeyFile.Text, vaPublicKey );
  481.       xRSA.Set_PublicKey( vaPublicKey );
  482.  
  483.       xEncryptor.EncryptionMethod := xRSA;
  484.     end;
  485.   except
  486.     on xErr : Exception do
  487.     begin
  488.       bPrepareOk := false;
  489.       ShowMessage( 'Error during EncryptionMethod initialization! : ' +
  490.                     xErr.Message );
  491.     end;
  492.   end;
  493.   PrepareEncryptionMethod := bPrepareOk;
  494. end;
  495.  
  496. {---------------------------------------------------------------}
  497. { Read the content of the specified file. Allegedly containing  }
  498. { a private or public key. Return the key in the vaKey          }
  499. { parameter.                                                    }
  500. {---------------------------------------------------------------}
  501. procedure TfrmMemoryEncrypt.ReadKeyFile( sKeyFile : string;
  502.                                          var vaKey : OleVariant );
  503. var
  504.   xFile   : TextFile;
  505.   sKey    : string;
  506.   pData   : Char;
  507. begin
  508.   vaKey := varEmpty;
  509.   if( length( sKeyFile ) > 0 )then
  510.   begin
  511.     AssignFile( xFile, sKeyFile );
  512.     Reset( xFile );
  513.     sKey := '';
  514.  
  515.     while not EOF( xFile ) do
  516.     begin
  517.       Read( xFile, pData );
  518.       sKey := sKey + pData;
  519.     end;
  520.     CloseFile( xFile );
  521.  
  522.     HexToBinary( sKey, vaKey );
  523.   end;
  524. end;
  525.  
  526. {---------------------------------------------------------------}
  527. { Save the current selected (and deselected) encryption type    }
  528. { (symmetric or asymmetric)                                     }
  529. {---------------------------------------------------------------}
  530. procedure TfrmMemoryEncrypt.SaveEncryptionType();
  531. var
  532.   xReg : TRegistryIniFile;
  533. begin
  534.   xReg := TRegistryIniFile.Create( 'Software\Xceed\Delphi\MemEncrypt' );
  535.   xReg.WriteBool( 'Encryption', 'Asymmetric', optAsymmetricEncryption.Checked );
  536.   xReg.WriteBool( 'Encryption', 'Symmetric', optSymmetricEncryption.Checked );
  537.   xReg.Free();
  538. end;
  539.  
  540. {---------------------------------------------------------------}
  541. { Save the current private key file name                        }
  542. {---------------------------------------------------------------}
  543. procedure TfrmMemoryEncrypt.SavePrivateKeyFileSetting();
  544. var
  545.   xReg : TRegistryIniFile;
  546. begin
  547.   xReg := TRegistryIniFile.Create( 'Software\Xceed\Delphi\MemEncrypt' );
  548.   xReg.WriteString( 'Encryption', 'PrivateKeyFile', edtPrivateKeyFile.Text );
  549.   xReg.Free();
  550. end;
  551.  
  552. {---------------------------------------------------------------}
  553. { Save the current public key file name                         }
  554. {---------------------------------------------------------------}
  555. procedure TfrmMemoryEncrypt.SavePublicKeyFileSetting();
  556. var
  557.   xReg : TRegistryIniFile;
  558. begin
  559.   xReg := TRegistryIniFile.Create( 'Software\Xceed\Delphi\MemEncrypt' );
  560.   xReg.WriteString( 'Encryption', 'PublicKeyFile', edtPublicKeyFile.Text );
  561.   xReg.Free();
  562. end;
  563.  
  564. end.
  565.  
  566.