![]() |
Frage zur Unterstützung von DEC5.1 zu DEC6.0
Hallo Zusammen
Ich habe aktuell die Aufgabe alten Code aus Delphi 7 (noch ohne Unicode-Support) der die DEC laut Headerinfo in Version: 3.0, Part I from Delphi Encryption Compendium (DEC Part I) verwendet auf D12 (Unicode) und mit DEC 6.x zu portieren. Ich hoffe es kann mich hierbei jemand dabei von euch unterstützen. Die folgenden Funktionen werden verwendet: HINWEIS: D7 = String => D12 = AnsiString D7 = PChar => D12 = PAnsiChar
Code:
So wie ich es verstehe, wird bei TCipher_Blowfish.Create, wenn der erste Parameter "Password" übergeben wird, wie folgt verfahren:
uses
DECUtil, Cipher, Hash; [..] function EncryptString(AValue: String; ACode: String; AFormat: Integer): String; begin Result := ''; TRY WITH (TCipher_Blowfish.Create(ACode, nil)) DO BEGIN TRY Result := CodeString(AValue, paEncode, AFormat); FINALLY Free; END; END; EXCEPT // END; end; function DecryptString(AValue: String; ACode: String; AFormat: Integer): String; begin Result := ''; TRY WITH (TCipher_Blowfish.Create(ACode, nil)) DO BEGIN TRY Result := CodeString(AValue, paDecode, AFormat); FINALLY Free; END; END; EXCEPT // END; end;
Code:
Also wird der AnsiString des Passwortes mit einem "Default Hash" berechnet und das wäre nach meinen Recherchen "THash_RipeMD256" oder liege ich hier bereits schon falsch?[... Auszug aus Cipher.pas ...] constructor TCipher.Create(const Password: String; AProtection: TProtection); begin inherited Create(AProtection); FHashClass := DefaultHashClass; GetContext(FBufSize, FKeySize, FUserSize); GetMem(FVector, FBufSize); GetMem(FFeedback, FBufSize); GetMem(FBuffer, FBufSize); GetMem(FUser, FUserSize); Protect; if Password <> '' then InitKey(Password, nil); end; [..] procedure TCipher.InitKey(const Key: String; IVector: Pointer); var I: Integer; begin Hash.Init; Hash.Calc(PChar(Key)^, Length(Key)); Hash.Done; I := Hash.DigestKeySize; if I > FKeySize then I := FKeySize; {generaly will truncate to large Keys} Init(Hash.DigestKey^, I, IVector); EncodeBuffer(Hash.DigestKey^, Hash.DigestKey^, Hash.DigestKeySize); Done; SetFlag(0, True); end; [..] function TProtection.CodeString(const Source: String; Action: TPAction; Format: Integer): String; var M: TMemoryStream; begin Result := ''; if Length(Source) <= 0 then Exit; M := TMemoryStream.Create; try if Action <> paDecode then Result := Source else Result := FormatToStr(PChar(Source), Length(Source), Format); M.Write(PChar(Result)^, Length(Result)); M.Position := 0; CodeStream(M, M, M.Size, Action); if Action = paDecode then begin SetLength(Result, M.Size); Move(M.Memory^, PChar(Result)^, M.Size); end else Result := StrToFormat(M.Memory, M.Size, Format); finally M.Free; end; end; [..] Hier also mein Übersetzungsversuch am Beispiel von DecryptString:
Code:
Leider kann ein mit der alten D7 Version verschlüsselter Wert mit der "portierten" D12 Version nicht entschlüsselt werden.
function DecryptString(AValue: AnsiString; ACode: AnsiString; AFormat: TDECFormat): AnsiString;
var DefHash: THash_RipeMD256; CodeHash: TBytes; Cipher: TCipher_Blowfish; begin Result := ''; try DefHash := THash_RipeMD256.Create; try DefHash.Init; CodeHash := DefHash.CalcString(ACode); DefHash.Done; finally DefHash.Free; end; Cipher := TCipher_Blowfish.Create; try Cipher.Init(CodeHash); try Result := Cipher.DecodeStringToString(AValue, AFormat); finally Cipher.Done; end; finally Cipher.Free; end; except // end; end; Wäre dankbar wenn mir hier jemand helfen könnte? |
AW: Frage zur Unterstützung von DEC5.1 zu DEC6.0
AValue auch als AnsiString.
Es gibt zwei DecodeStringToString und du benötigst die ANSI-Version. ![]() |
AW: Frage zur Unterstützung von DEC5.1 zu DEC6.0
Hab die Anpassung (auch im Code oben) durchgeführt. Aber die Entschlüsselung schlägt weiterhin fehl. Ich vermute hier ein Problem mit dem Hash oder dem IVector?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz