Thema: Delphi Probleme mit DCPcrypt

Einzelnen Beitrag anzeigen

DLX

Registriert seit: 17. Apr 2018
20 Beiträge
 
#29

AW: Probleme mit DCPcrypt

  Alt 28. Mai 2018, 12:41
So funktioniert es nun
Code:
function DecryptText(input:string):String;
var Cipher : TDCP_rijndael;
    Data, Key, IV : ansistring;
    index, dataLength, bsize, pad: integer;

begin
  //key := '12345678901234567890123456789012';
  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 := ord(Data[length(Data)]);
    for index :=1 to pad do delete(Data,length(Data),1);
  finally
    Cipher.Burn;
    Cipher.Free;
  end;

  Result:=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 := 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;
Um also einen Schlüssel länger als 32 Zeichen zu nehmen müsste ich dann auf 256bits umstellen bei dem Cipher.init ?
  Mit Zitat antworten Zitat