unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,DCPcrypt2, DCPblockciphers, DCPrijndael, DCPbase64,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function DecryptText():String;
var Cipher : TDCP_rijndael;
Data, Key, IV : ansistring;
index, dataLength, bsize, pad: integer;
begin
key := '12345678901234567890123456789012';
IV := '1234567890123456';
Data := form1.Edit1.text;
Data := DCPBase64.Base64DecodeStr(Data);
Cipher := TDCP_rijndael.Create(nil);
try
Cipher.Init(Key[1],128,@IV[1]);
Cipher.DecryptCBC(Data[1],Data[1],Length(Data));
finally
Cipher.Burn;
Cipher.Free;
end;
form1.Memo1.Lines.Add(Data);
end;
function EncryptText():String;
var Cipher : TDCP_rijndael;
Data,DataDec, Key, IV : ansistring;
index, dataLength, bsize, pad: integer;
begin
key := '12345678901234567890123456789012';
IV := '1234567890123456';
//Data := 'thisis128bitstxt';
Data := form1.edit1.text;
Cipher := TDCP_rijndael.Create(nil);
try
Cipher.Init(Key[1],128,@IV[1]);
//don't miss padding
{start padding}
dataLength := Length(Data);
bsize := (Cipher.BlockSize div 8);
pad := bsize - (dataLength mod bsize);
for index := 1 to pad do
Data := Data+chr(pad);
{end padding}
Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
finally
Cipher.Burn;
Cipher.Free;
end;
Data := DCPBase64.Base64EncodeStr(Data);
form1.Memo1.Lines.Add(Data);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EncryptText();
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DecryptText();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.