Download source code

procedure TForm1.GetProviderTypes(AList: TStrings);
var
  i, provType, len: DWORD;
  p: PChar;
begin
  i := 0;
  while CryptEnumProviderTypes(i, nil, 0, @provType, nil, @len) do
  begin
    GetMem(p, len);
    try
      if not CryptEnumProviderTypes(i, nil, 0, @provType, p, @len) then
      begin
        raise Exception.CreateFmt('CryptEnumProviderTypes error - %d', [GetLastError()]);
      end;
      AList.Add(string(p) + ' (' + IntToStr(provType) + ')');
    finally
      FreeMem(p);
    end;
    Inc(i);
  end;
end;
 
procedure TForm1.GetProviders(AList: TStrings);
var
  i, provType, len: DWORD;
  p: PChar;
begin
  i := 0;
  while CryptEnumProviders(i, nil, 0, @provType, nil, @len) do
  begin
    GetMem(p, len);
    try
      if not CryptEnumProviders(i, nil, 0, @provType, p, @len) then
      begin
        raise Exception.CreateFmt('CryptEnumProviderTypes error - %d', [GetLastError()]);
      end;
      AList.Add(string(p) + ' (' + IntToStr(provType) + ')');
    finally
      FreeMem(p);
    end;
    Inc(i);
  end;
end;
 
procedure TForm1.GetPackages(AList: TStrings);
var
  sspi: TclSspi;
  PackagesCount: Cardinal;
  PackageInfoArray, pkg: PSecPkgInfo;
  i: Integer;
begin
  sspi := TclSspi.Create();
  try
    sspi.FunctionTable.EnumerateSecurityPackages(PackagesCount, PackageInfoArray);
 
    for i := 0 to PackagesCount - 1 do
    begin
      pkg := PSecPkgInfo(Integer(PackageInfoArray) + SizeOf(TSecPkgInfo) * i);
      AList.Add(string(pkg.Name) + '  (' + string(pkg.Comment) + ')');
    end;
  finally
    sspi.FunctionTable.FreeContextBuffer(PackageInfoArray);
    sspi.Free();
  end;
end;

Add Feedback