Andreas Software - Source Code - KSADLL.PAS

Dynamically load my little DLL file KSA.DLL in Embarcadero Delphi and use it to make encryption keys from passwords


unit KSADLL;

{
  Dynamically load my little DLL file KSA.DLL in Embarcadero Delphi and use it to make encryption keys from passwords. It's a key strengthening algorithm that uses SHA-3 and it performs 1 + (IntStrength * 1024) number of hashes. Valid numbers for IntStrength are 32, 64, 128, 256, 512 and 1024. Valid numbers for IntBits are 224, 256, 384 and 512. The returned string is hex encoded. The DLL file is Unicode and is available in both x64 and x86 variants. Download the DLL file here:

  https://www.andreas-software.com/KSA.DLL.ZIP

  https://www.andreas-software.com/KSA-X86.DLL.ZIP
}

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes;

function MakeKSAHexKey(StrPassword: string; IntStrength: NativeInt = 128; IntBits: NativeInt = 256): string;

implementation

type
  TMakeKSAHexKeyFunction = function(StrPassword: PWideChar; IntStrength: NativeInt; IntBits: NativeInt; OutputBuffer: Pointer): NativeInt; stdcall;

function MakeKSAHexKey(StrPassword: string; IntStrength: NativeInt = 128; IntBits: NativeInt = 256): string;
var DLLFileName: string;
var DLLFunctionName: string;
var DLLHandle: NativeUInt;
var MakeKSAHexKeyFunction: TMakeKSAHexKeyFunction;
begin
  Result := '';
  if StrPassword <> '' then begin
    if (IntStrength = 32) or (IntStrength = 64) or (IntStrength = 128) or (IntStrength = 256) or (IntStrength = 512) or (IntStrength = 1024) then begin
      if (IntBits = 224) or (IntBits = 256) or (IntBits = 384) or (IntBits = 512) then begin
        DLLFileName := 'KSA';
        {$IFDEF WIN32}
          DLLFileName := DLLFileName + '-X86';
        {$ENDIF}
        DLLFileName := DLLFileName + '.DLL';
        DLLFunctionName := 'MakeKSAHexKey';
        DLLHandle := LoadLibrary(PWideChar(DLLFileName));
        if DLLHandle <> 0 then begin
          @MakeKSAHexKeyFunction := GetProcAddress(DLLHandle, PWideChar(DLLFunctionName));
          if Assigned(MakeKSAHexKeyFunction) = True then begin
            SetLength(Result, (IntBits div 8) * 2);
            if MakeKSAHexKeyFunction(PWideChar(StrPassword), IntStrength, IntBits, Pointer(Result)) = (((IntBits div 8) * 2) * 2) then begin
              // OK.
            end
            else begin
              Result := '';
            end;
          end;
          FreeLibrary(DLLHandle);
        end;
      end;
    end;
  end;
end;

end.

[ Source Code ]

In Swedish?
View this page in Swedish