home *** CD-ROM | disk | FTP | other *** search
- {*******************************************************************************
- * Unit : frmCipherTest *
- ********************************************************************************
- * Purpose : Provides a testing harness for TSM encryption components *
- ********************************************************************************
- * Copyright : This unit is copyright TSM Inc. (Ian Sparkes) 1998. *
- * This source code may not be distributed to third parties in *
- * or in part without the written permission of TSM Inc. *
- * All rights reserved. Liability limited to replacement of *
- * this original source code in the case of loss or damage because *
- * the use or misuse of this software. *
- ********************************************************************************
- * Version : 25.02.98 - 1.0 Original unit *
- * 10.08.98 - 1.10 Tidied up *
- *******************************************************************************}
-
- unit frmctest;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls,
- blowfish, ExtCtrls;
-
- {*******************************************************************************
- * Type : TfrmCipherTest *
- ********************************************************************************
- * Purpose : Defines the form *
- *******************************************************************************}
- type
- TfrmCipherTest = class(TForm)
- grpText: TGroupBox;
- btnDecrypt: TButton;
- btnEncrypt: TButton;
- edtTestText: TEdit;
- lblTestText: TLabel;
- grpFile: TGroupBox;
- btnFileEncrypt: TButton;
- odlFileEnc: TOpenDialog;
- sdlFileEnc: TSaveDialog;
- btnFileDecrypt: TButton;
- odlFileDec: TOpenDialog;
- sdlFileDec: TSaveDialog;
- rgrMode: TRadioGroup;
- rdbECB: TRadioButton;
- rdbCBC: TRadioButton;
- rdbCFB: TRadioButton;
- rdbOFB: TRadioButton;
- edtVersion: TEdit;
- lblVersion: TLabel;
- Bevel1: TBevel;
- Blowfish1: TBlowfish;
- procedure btnFileEncryptClick(Sender: TObject);
- procedure btnEncryptClick(Sender: TObject);
- procedure btnDecryptClick(Sender: TObject);
- procedure btnFileDecryptClick(Sender: TObject);
- procedure rdbECBClick(Sender: TObject);
- procedure rdbCBCClick(Sender: TObject);
- procedure rdbCFBClick(Sender: TObject);
- procedure rdbOFBClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- end;
-
- var
- frmCipherTest: TfrmCipherTest;
-
- implementation
-
- {$R *.DFM}
-
- {*******************************************************************************
- * Procedure : btnEncryptClick *
- ********************************************************************************
- * Purpose : Encrypts a the line of text in the edit box *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.btnEncryptClick(Sender: TObject);
- var
- Tempstr: string;
- begin
- Blowfish1.LoadIVString('Init Vector');
- Blowfish1.InitialiseString('Pass Phrase');
-
- // encrypt the string
- Blowfish1.EncryptString(edtTestText.Text, TempStr);
-
- // and copy it back to the edit box
- edtTestText.Text := TempStr;
-
- // destroy sensitive information
- Blowfish1.Burn;
- end; {btnEncryptClick}
-
- {*******************************************************************************
- * Procedure : btnDecryptClick *
- ********************************************************************************
- * Purpose : Decrypts a the line of text in the edit box *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.btnDecryptClick(Sender: TObject);
- var
- Tempstr: string;
- begin
- Blowfish1.InitialiseString('Pass Phrase');
- Blowfish1.LoadIVString('Init Vector');
-
- // decrypt the string
- Blowfish1.DecryptString(edtTestText.Text,Tempstr);
-
- // and copy it back into the edit box
- edtTestText.Text := TempStr;
-
- // destroy sensitive information
- Blowfish1.Burn;
- end; {btnDecryptClick}
-
- {*******************************************************************************
- * Procedure : btnFileEncryptClick *
- ********************************************************************************
- * Purpose : Selects a file to encrypt and encrypts it to the specified *
- * destination file *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.btnFileEncryptClick(Sender: TObject);
- begin
- Blowfish1.LoadIVString('Init Vector');
- Blowfish1.InitialiseString('Pass Phrase');
-
- // check if a source and destination file has been selected
- if odlFileEnc.Execute and sdlFileEnc.Execute then
- begin
- // perform the encryption
- Blowfish1.EncryptFile(odlFileEnc.FileName, sdlFileEnc.FileName);
- end; {if}
-
- // destroy sensitive information
- Blowfish1.Burn;
- end; {btnFileEncryptClick}
-
- {*******************************************************************************
- * Procedure : btnFileDecryptClick *
- ********************************************************************************
- * Purpose : Selects a file to decrypt and decrypts it to the specified *
- * destination file *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.btnFileDecryptClick(Sender: TObject);
- begin
- Blowfish1.LoadIVString('Init Vector');
- Blowfish1.InitialiseString('Pass Phrase');
-
- // check if a source and destination file has been selected
- if odlFileDec.Execute and sdlFileDec.Execute then
- begin
- // perform the decryption
- Blowfish1.DecryptFile(odlFileDec.FileName, sdlFileDec.FileName);
- end;
-
- // destroy sensitive information
- Blowfish1.Burn;
- end; {btnFileDecryptClick}
-
- {*******************************************************************************
- * Procedure : rdbECBClick *
- ********************************************************************************
- * Purpose : Sets the cipher mode to ECB *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.rdbECBClick(Sender: TObject);
- begin
- Blowfish1.CipherMode := ECB;
- end; {rdbECBClick}
-
- {*******************************************************************************
- * Procedure : rdbCBCClick *
- ********************************************************************************
- * Purpose : Sets the cipher mode to CBC *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.rdbCBCClick(Sender: TObject);
- begin
- Blowfish1.CipherMode := CBC;
- end; {rdbCBCClick}
-
- {*******************************************************************************
- * Procedure : rdbCFBClick *
- ********************************************************************************
- * Purpose : Sets the cipher mode to CFB *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.rdbCFBClick(Sender: TObject);
- begin
- Blowfish1.CipherMode := CFB;
- end; {rdbCFBClick}
-
- {*******************************************************************************
- * Procedure : rdbOFBClick *
- ********************************************************************************
- * Purpose : Sets the cipher mode to OFB *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.rdbOFBClick(Sender: TObject);
- begin
- Blowfish1.CipherMode := OFB;
- end; {rdbOFBClick}
-
- {*******************************************************************************
- * Procedure : FormCreate *
- ********************************************************************************
- * Purpose : Retrieves the cipher version and set the cipher mode to ECB *
- ********************************************************************************
- * Paramters : None *
- ********************************************************************************
- * Returns : None *
- *******************************************************************************}
- procedure TfrmCipherTest.FormCreate(Sender: TObject);
- begin
- edtVersion.Text := Blowfish1.GetVersion;
- rdbECBClick(Self);
- end; {FormCreate}
-
- end.
-