TurboPack / LockBox

LockBox is a Delphi and C++Builder library for cryptography.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LbString and DESEncryptStringEx not found in the latest version of TpLockBock

PlanetIrata opened this issue · comments

commented

Hi, how would you convert this code which doesn't compile anymore with the latest version of TpLockBox (DESEncryptStringEx was in the LbString unit):

function CipherString(const AString: string; APassPhrase: string): string;
var
  Key64: TKey64;
begin
  LbCipher.GenerateLMDKey(Key64, sizeof(Key64), APassPhrase);
  Result := DESEncryptStringEx(AString, Key64, True);
end;

Thanks !

You have to call TDES.EncryptDES

commented

Got it... for anyone interested here is the converted code:

function CipherString(const AString: string; APassPhrase: string): string;
var
  DES: TLbDES;
begin
  DES := TLbDES.Create(nil);
  try
    // Very important if you need do encrypt/decrypt strings encrypted with the legacy version of TpLockBox!
    // in the previous version of TpLockbox, a N character Passphrase has 2xN TBytes (5 characters = 10 bytes)
    // where in the new version, a N character Passphrase has N TBytes (5 characters = 5 bytes) with the default encoding
    DES.Encoding := TEncoding.Unicode;

    DES.GenerateKey(APassPhrase);
    Result := DES.EncryptString(AString);
  finally
    FreeAndNil(DES);
  end;
end;