home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / D4 / BLOWNREG.ZIP / EXAMPLES / BLOWTEST / FRMCTEST.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1998-08-17  |  12.0 KB  |  247 lines

  1. {*******************************************************************************
  2. * Unit      : frmCipherTest                                                    *
  3. ********************************************************************************
  4. * Purpose   : Provides a testing harness for TSM encryption components         *
  5. ********************************************************************************
  6. * Copyright : This unit is copyright TSM Inc. (Ian Sparkes) 1998.              *
  7. *             This source code may not be distributed to third parties in      *
  8. *             or in part without the written permission of TSM Inc.            *
  9. *             All rights reserved. Liability limited to replacement of         *
  10. *             this original source code in the case of loss or damage because  *
  11. *             the use or misuse of this software.                              *
  12. ********************************************************************************
  13. * Version   : 25.02.98  - 1.0   Original unit                                  *
  14. *             10.08.98  - 1.10  Tidied up                                      *
  15. *******************************************************************************}
  16.  
  17. unit frmctest;
  18.  
  19. interface
  20.  
  21. uses
  22.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls,
  23.   blowfish, ExtCtrls;
  24.  
  25. {*******************************************************************************
  26. * Type      : TfrmCipherTest                                                   *
  27. ********************************************************************************
  28. * Purpose   : Defines the form                                                 *
  29. *******************************************************************************}
  30. type
  31.   TfrmCipherTest = class(TForm)
  32.     grpText: TGroupBox;
  33.     btnDecrypt: TButton;
  34.     btnEncrypt: TButton;
  35.     edtTestText: TEdit;
  36.     lblTestText: TLabel;
  37.     grpFile: TGroupBox;
  38.     btnFileEncrypt: TButton;
  39.     odlFileEnc: TOpenDialog;
  40.     sdlFileEnc: TSaveDialog;
  41.     btnFileDecrypt: TButton;
  42.     odlFileDec: TOpenDialog;
  43.     sdlFileDec: TSaveDialog;
  44.     rgrMode: TRadioGroup;
  45.     rdbECB: TRadioButton;
  46.     rdbCBC: TRadioButton;
  47.     rdbCFB: TRadioButton;
  48.     rdbOFB: TRadioButton;
  49.     edtVersion: TEdit;
  50.     lblVersion: TLabel;
  51.     Bevel1: TBevel;
  52.     Blowfish1: TBlowfish;
  53.     procedure btnFileEncryptClick(Sender: TObject);
  54.     procedure btnEncryptClick(Sender: TObject);
  55.     procedure btnDecryptClick(Sender: TObject);
  56.     procedure btnFileDecryptClick(Sender: TObject);
  57.     procedure rdbECBClick(Sender: TObject);
  58.     procedure rdbCBCClick(Sender: TObject);
  59.     procedure rdbCFBClick(Sender: TObject);
  60.     procedure rdbOFBClick(Sender: TObject);
  61.     procedure FormCreate(Sender: TObject);
  62.   end;
  63.  
  64. var
  65.   frmCipherTest: TfrmCipherTest;
  66.  
  67. implementation
  68.  
  69. {$R *.DFM}
  70.  
  71. {*******************************************************************************
  72. * Procedure : btnEncryptClick                                                  *
  73. ********************************************************************************
  74. * Purpose   : Encrypts a the line of text in the edit box                      *
  75. ********************************************************************************
  76. * Paramters : None                                                             *
  77. ********************************************************************************
  78. * Returns   : None                                                             *
  79. *******************************************************************************}
  80. procedure TfrmCipherTest.btnEncryptClick(Sender: TObject);
  81. var
  82.      Tempstr: string;
  83. begin
  84.      Blowfish1.LoadIVString('Init Vector');
  85.      Blowfish1.InitialiseString('Pass Phrase');
  86.  
  87.      // encrypt the string
  88.      Blowfish1.EncryptString(edtTestText.Text, TempStr);
  89.  
  90.      // and copy it back to the edit box
  91.      edtTestText.Text := TempStr;
  92.  
  93.      // destroy sensitive information
  94.      Blowfish1.Burn;
  95. end; {btnEncryptClick}
  96.  
  97. {*******************************************************************************
  98. * Procedure : btnDecryptClick                                                  *
  99. ********************************************************************************
  100. * Purpose   : Decrypts a the line of text in the edit box                      *
  101. ********************************************************************************
  102. * Paramters : None                                                             *
  103. ********************************************************************************
  104. * Returns   : None                                                             *
  105. *******************************************************************************}
  106. procedure TfrmCipherTest.btnDecryptClick(Sender: TObject);
  107. var
  108.      Tempstr: string;
  109. begin
  110.      Blowfish1.InitialiseString('Pass Phrase');
  111.      Blowfish1.LoadIVString('Init Vector');
  112.  
  113.      // decrypt the string
  114.      Blowfish1.DecryptString(edtTestText.Text,Tempstr);
  115.  
  116.      // and copy it back into the edit box
  117.      edtTestText.Text := TempStr;
  118.  
  119.      // destroy sensitive information
  120.      Blowfish1.Burn;
  121. end; {btnDecryptClick}
  122.  
  123. {*******************************************************************************
  124. * Procedure : btnFileEncryptClick                                              *
  125. ********************************************************************************
  126. * Purpose   : Selects a file to encrypt and encrypts it to the specified       *
  127. *             destination file                                                 *
  128. ********************************************************************************
  129. * Paramters : None                                                             *
  130. ********************************************************************************
  131. * Returns   : None                                                             *
  132. *******************************************************************************}
  133. procedure TfrmCipherTest.btnFileEncryptClick(Sender: TObject);
  134. begin
  135.      Blowfish1.LoadIVString('Init Vector');
  136.      Blowfish1.InitialiseString('Pass Phrase');
  137.  
  138.      // check if a source and destination file has been selected
  139.      if odlFileEnc.Execute and sdlFileEnc.Execute then
  140.      begin
  141.           // perform the encryption
  142.           Blowfish1.EncryptFile(odlFileEnc.FileName, sdlFileEnc.FileName);
  143.      end; {if}
  144.  
  145.      // destroy sensitive information
  146.      Blowfish1.Burn;
  147. end; {btnFileEncryptClick}
  148.  
  149. {*******************************************************************************
  150. * Procedure : btnFileDecryptClick                                              *
  151. ********************************************************************************
  152. * Purpose   : Selects a file to decrypt and decrypts it to the specified       *
  153. *             destination file                                                 *
  154. ********************************************************************************
  155. * Paramters : None                                                             *
  156. ********************************************************************************
  157. * Returns   : None                                                             *
  158. *******************************************************************************}
  159. procedure TfrmCipherTest.btnFileDecryptClick(Sender: TObject);
  160. begin
  161.      Blowfish1.LoadIVString('Init Vector');
  162.      Blowfish1.InitialiseString('Pass Phrase');
  163.  
  164.      // check if a source and destination file has been selected
  165.      if odlFileDec.Execute and sdlFileDec.Execute then
  166.      begin
  167.           // perform the decryption
  168.           Blowfish1.DecryptFile(odlFileDec.FileName, sdlFileDec.FileName);
  169.      end;
  170.  
  171.      // destroy sensitive information
  172.      Blowfish1.Burn;
  173. end; {btnFileDecryptClick}
  174.  
  175. {*******************************************************************************
  176. * Procedure : rdbECBClick                                                      *
  177. ********************************************************************************
  178. * Purpose   : Sets the cipher mode to ECB                                      *
  179. ********************************************************************************
  180. * Paramters : None                                                             *
  181. ********************************************************************************
  182. * Returns   : None                                                             *
  183. *******************************************************************************}
  184. procedure TfrmCipherTest.rdbECBClick(Sender: TObject);
  185. begin
  186.      Blowfish1.CipherMode := ECB;
  187. end; {rdbECBClick}
  188.  
  189. {*******************************************************************************
  190. * Procedure : rdbCBCClick                                                      *
  191. ********************************************************************************
  192. * Purpose   : Sets the cipher mode to CBC                                      *
  193. ********************************************************************************
  194. * Paramters : None                                                             *
  195. ********************************************************************************
  196. * Returns   : None                                                             *
  197. *******************************************************************************}
  198. procedure TfrmCipherTest.rdbCBCClick(Sender: TObject);
  199. begin
  200.      Blowfish1.CipherMode := CBC;
  201. end; {rdbCBCClick}
  202.  
  203. {*******************************************************************************
  204. * Procedure : rdbCFBClick                                                      *
  205. ********************************************************************************
  206. * Purpose   : Sets the cipher mode to CFB                                      *
  207. ********************************************************************************
  208. * Paramters : None                                                             *
  209. ********************************************************************************
  210. * Returns   : None                                                             *
  211. *******************************************************************************}
  212. procedure TfrmCipherTest.rdbCFBClick(Sender: TObject);
  213. begin
  214.      Blowfish1.CipherMode := CFB;
  215. end; {rdbCFBClick}
  216.  
  217. {*******************************************************************************
  218. * Procedure : rdbOFBClick                                                      *
  219. ********************************************************************************
  220. * Purpose   : Sets the cipher mode to OFB                                      *
  221. ********************************************************************************
  222. * Paramters : None                                                             *
  223. ********************************************************************************
  224. * Returns   : None                                                             *
  225. *******************************************************************************}
  226. procedure TfrmCipherTest.rdbOFBClick(Sender: TObject);
  227. begin
  228.      Blowfish1.CipherMode := OFB;
  229. end; {rdbOFBClick}
  230.  
  231. {*******************************************************************************
  232. * Procedure : FormCreate                                                       *
  233. ********************************************************************************
  234. * Purpose   : Retrieves the cipher version and set the cipher mode to ECB      *
  235. ********************************************************************************
  236. * Paramters : None                                                             *
  237. ********************************************************************************
  238. * Returns   : None                                                             *
  239. *******************************************************************************}
  240. procedure TfrmCipherTest.FormCreate(Sender: TObject);
  241. begin
  242.      edtVersion.Text := Blowfish1.GetVersion;
  243.      rdbECBClick(Self);
  244. end; {FormCreate}
  245.  
  246. end.
  247.