MHumm / DelphiEncryptionCompendium

Cryptographic library for Embarcadero Delphi and potentially for FPC as well
Apache License 2.0
257 stars 66 forks source link

Can't execute PBKDF2 key derivation function. Please help #42

Closed Baylung closed 2 years ago

Baylung commented 2 years ago

I'm having Abstract error: TDECHashAuthentication is not implemented error when calling PBKDF2 function

aes_key, Password, Salt : TBytes;
...
aes_key := TDECHashAuthentication.PBKDF2( Password, Salt, 100000, 32 );

In the TDECHashAuthentication source code there are no implementation of DigestSize, and the exception raised from here:

class function TDECHash.DigestSize: UInt32;
begin
  // C++ does not support virtual static functions thus the base cannot be
  // marked 'abstract'. This is our workaround:
  raise EDECAbstractError.Create(GetShortClassName);
end;

Please help, how to make working PBKDF2 ?

[help wanted, delphi, question]

Baylung commented 2 years ago

Found the answer by myself. I was calling abstract class, changed to THash_SHA256 and it is working now:

  sha256_hash := THash_SHA256.Create;
  aes_key := sha256_hash.PBKDF2( Password, Salt, 100000, 32 );