unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
DCPcrypt2, DCPblockciphers, DCPrijndael, DCPbase64;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
eText: TEdit;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
eKey: TEdit;
eMKey: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function DecryptText( Data, Key, MasterKey: AnsiString ):
String;
var Cipher : TDCP_rijndael;
index, dataLength, bsize, pad: integer;
begin
Data := DCPBase64.Base64DecodeStr(Data);
Cipher := TDCP_rijndael.Create(
NIL);
try
Cipher.Init(Key[1],128,@MasterKey[1]);
Cipher.DecryptCBC(Data[1],Data[1],Length(Data));
if form1.CheckBox1.Checked
then
begin
pad := ord(Data[length(Data)]);
SetLength(Data, length(Data)-pad);
end;
finally
Cipher.Burn;
Cipher.Free;
end;
if form1.CheckBox2.Checked
then
form1.Memo1.Lines.Add(Trim(Data))
else form1.Memo1.Lines.Add(Data);
if form1.CheckBox2.Checked
then
form1.eText.Text := Trim(Data)
else form1.eText.Text := Data;
end;
function EncryptText( Data, Key, MasterKey: AnsiString ):
String;
var Cipher : TDCP_rijndael;
{Data,}DataDec
{, Key, IV }: ansistring;
index, dataLength, bsize, pad: integer;
begin
Cipher := TDCP_rijndael.Create(
nil);
try
Cipher.Init(Key[1],128,@MasterKey[1]);
dataLength := Length(Data);
bsize := (Cipher.BlockSize
div 8);
pad := bsize - (dataLength
mod bsize);
for index := 1
to pad
do
Data := Data+chr(pad);
Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
finally
Cipher.Burn;
Cipher.Free;
end;
Data := DCPBase64.Base64EncodeStr(Data);
form1.Memo1.Lines.Add(Data);
form1.eText.Text := Data;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EncryptText(eText.Text, eKey.Text, eMKey.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DecryptText(eText.Text, eKey.Text, eMKey.Text);
end;
end.