AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign Dateien verschlüssen mit Wolgang Ehrhardts Crypt-Units
Thema durchsuchen
Ansicht
Themen-Optionen

Dateien verschlüssen mit Wolgang Ehrhardts Crypt-Units

Ein Thema von DieDolly · begonnen am 16. Dez 2020 · letzter Beitrag vom 7. Jan 2021
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.376 Beiträge
 
Delphi 12 Athens
 
#21

AW: Dateien verschlüssen mit Wolgang Ehrhardts Crypt-Units

  Alt 17. Dez 2020, 13:50
Ist es wirklich so schwer zu verstehen?

Entweder du reichts es einfach durch und kannst hier von außen z.B. deine Form/Self reingeben, oder sonsteine Instanz, wo dieses Interface enthalten ist.
Delphi-Quellcode:
type
  TDECCryptUtils = record
  private
    //
  public
    class function AESFileEncrypt(const FileName, Password: string; const Progress: IDECProgress = nil): string; static;
    class function AESFileDecrypt(const FileName, Password: string; const Progress: IDECProgress = nil): string; static;
  end;

class function TDECCryptUtils.AESFileDecrypt(const FileName, Password: string; const Progress: IDECProgress): string;
...
   Cipher.DecodeFile(FileName, FileName + '.decrypted.txt', Process);



type
  TForm1 = class(TForm, IDECProgress)
  ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDECCryptUtils.AESFileDecrypt('Dat.ei', 'Pass', Self);
end;
Und im Notfalls kann man es auch immer kapseln, sich also Wrapper bauen, um zwischen den verschiedenen Möglichkeiten der Callbacks zu wechseln.
Delphi-Quellcode:
type
type
  TDECProgress = procedure(const Min, Max, Pos: Int64) of object; // oder ohne "of object" oder mit "reference to" und mit oder ohne "stdcall"

  TDECProgressWrapper = class(TInterfacedObject, IDECProgress);
  private
    FOnProcess: TDECProgress;
    procedure Process(const Min, Max, Pos: Int64); stdcall;
  public
    constructor Create(const OnProcess: TDECProgress);
  end;

  TDECCryptUtils = record
  private
    //
  public
    class function AESFileEncrypt(const FileName, Password: string; const OnProgress: TDECProgress = nil): string; static;
    class function AESFileDecrypt(const FileName, Password: string; const OnProgress: TDECProgress = nil): string; static;
  end;

procedure TDECProgress.Process(const Min, Max, Pos: Int64); stdcall;
begin
  FOnProcess(Min, Max, Pos);
end;

constructor TDECProgress.Create(const OnProcess: TDECProgress);
begin
  inherited;
  Assert(Assigned(AProcess));
  FOnProcess := OnProcess;
end;

class function TDECCryptUtils.AESFileDecrypt(const FileName, Password: string; const OnProgress: TDECProgress): string;
...
   Cipher.DecodeFile(FileName, FileName + '.decrypted.txt', TDECProgressWrapper.Create(OnProgress)); // nur wenn Assigned(OnProgress) ... oder oben das Assert entfernen (und if-Assigned in den Callback)



type
  TForm1 = class(TForm) // ohne IDECProgress
  ...

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDECCryptUtils.AESFileDecrypt('Dat.ei', 'Pass', YourProcessMethod);
end;
Zitat:
Delphi-Quellcode:
  except
   //
  end;
Für sowas gehört man mindestens gevierteilt.
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (17. Dez 2020 um 13:58 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:25 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