Ich hab die beiden funktionen nun so gemacht:
Code:
function DecryptText(input:string):String;
var Cipher : TDCP_rijndael;
Data, Key, IV : ansistring;
index, dataLength, bsize, pad: integer;
begin
key := '12345678901234567890123456789012';
IV := '1234567890123456';
Data := input;
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));
pad := 16- ord(Data[length(Data)]);
for index :=1 to pad do delete(Data,length(Data),1);
finally
Cipher.Burn;
Cipher.Free;
end;
Result:=trim(Data);
end;
function EncryptText(input:string):String;
var Cipher : TDCP_rijndael;
Data,DataDec, Key, IV : ansistring;
index, dataLength, bsize, pad: integer;
begin
key := '12345678901234567890123456789012';
IV := '1234567890123456';
//Data := 'thisis128bitstxt';
Data := input;
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);
Result:=Data;
end;
Text: Heute sitze ich hier und teste es sehr doll
Crypted:1r4gz8+TFpWBvykCVx9YJp5fVQKx2z3XidDLsq5S0W ZeEiUmXoqgLe5wVDklJ4kU
wenn ich das dann wieder entschlüssel
Crypted: 1r4gz8+TFpWBvykCVx9YJp5fVQKx2z3XidDLsq5S0WZeEiUmXo qgLe5wVDklJ4kU
Text: Heute sitze ich hier und teste es seh
Es fehlt also was, was mach ich falsch ?