Einzelnen Beitrag anzeigen

Benutzerbild von xZise
xZise

Registriert seit: 3. Mär 2006
Ort: Waldbronn
4.303 Beiträge
 
Delphi 2009 Professional
 
#3

Re: [DEC] WideString ver/entschlüsseln

  Alt 1. Jan 2008, 21:32
Also so funktioniert es leider nicht:
Delphi-Quellcode:
function Encode(const Key: String; const Text: String): String;
var
  Salt: Binary;
begin
  with TCipher_Rijndael.Create do
  try
    Mode := cmCBCx;
    Salt := RandomBinary(16);
    Init(THash_SHA1.KDFx(Key, Salt, Context.KeySize));
    Result := TFormat_MIME64.Encode(Salt + EncodeBinary(Text));
  finally
    Free;
  end;
end;

function Decode(const Key: String; const Text: String): String;
var
  Data: Binary;
begin
  with TCipher_Rijndael.Create do
  try
    Mode := cmCBCx;
    Data := TFormat_MIME64.Decode(Text);
    Init(THash_SHA1.KDFx(Key, Copy(Data, 1, 16), Context.KeySize));
    Result := DecodeBinary(Copy(Data, 16, MaxInt));
  finally
    Free;
    ProtectBinary(Data);
  end;
end;
Wenn ich nun ein Passwort nehme und einen Text (WideString) bekomme ich nur die 4 letzten Zeichen wieder zurück.

Delphi-Quellcode:
str := Encode(frmPassword.mePasswd.Text, App.GetText);
ShowMessage(Decode(frmPassword.mePasswd.Text, str));
MfG
xZise
Fabian
Eigentlich hat MS Windows ab Vista den Hang zur Selbstzerstörung abgewöhnt – mkinzler
  Mit Zitat antworten Zitat