AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Der DEC x32 ASM in x64/PurePascal Konvertierungsthread
Thema durchsuchen
Ansicht
Themen-Optionen

Der DEC x32 ASM in x64/PurePascal Konvertierungsthread

Ein Thema von Assertor · begonnen am 7. Jan 2012 · letzter Beitrag vom 17. Sep 2020
 
Jens01
Online

Registriert seit: 14. Apr 2009
673 Beiträge
 
#16

AW: Der DEC x32 ASM in x64/PurePascal Konvertierungsthread

  Alt 2. Dez 2013, 21:31
So habe ich das gemacht. Das ist anscheinend von mir aus einem Beispiel von ihm zusammengestrickt :

Delphi-Quellcode:
function Encrypt(const AText: string; const APassword: string): string;
{ -Encrypt file InName to OutName using password }
// http://www.wolfgang-ehrhardt.de/crypt_en.html
const
  bufSize = $C000;
var
  N : word;
  len : int64;
  hdr : TFCA256Hdr;
  cxe : TAES_EAXContext;
  auth : TFCA256_AuthBlock;
  TextOut, TextIn: TStringStream;
  buf : array [0 .. bufSize - 1] of Byte;
begin
  randomize;
  TextIn := TStringStream.Create(AText);
  TextOut := TStringStream.Create;
  try
    len := TextIn.Size;
    GetSalt(hdr.salt);

    if FCA_EAX256_initS(cxe, APassword, hdr) <> 0 then
      raise Exception.Create('Fehler');

    TextOut.WriteBuffer(hdr, SizeOf(hdr));

    while len > 0 do
    begin
      if len > SizeOf(buf) then
        N := SizeOf(buf)
      else
        N := len;
      TextIn.ReadBuffer(buf, N);
      dec(len, N);
      if FCA_EAX256_encrypt(cxe, buf, N) <> 0 then
        raise Exception.Create('Fehler');
      TextOut.WriteBuffer(buf, N);
    end;
    FCA_EAX256_final(cxe, auth);
    TextOut.WriteBuffer(auth, SizeOf(auth));
    Result := Base64EncStr(TextOut.DataString);
  finally
    TextOut.Free;
    TextIn.Free;
  end;
end;

function Decrypt(const AText: string; const APassword: string): string;
{ -Decrypt file InName to OutName using password sPW }
// http://www.wolfgang-ehrhardt.de/crypt_en.html
const
  bufSize = $C000;
var
  N : word;
  I, len : longint;
  hdrk : TFCA256Hdr;
  hdrf : TFCA256Hdr;
  cxe : TAES_EAXContext;
  cxh : TFCA_HMAC256_Context;
  authf : TFCA256_AuthBlock;
  authc : TFCA256_AuthBlock;
  UseEAX : boolean;
  TextOut, TextIn: TStringStream;
  buf : array [0 .. bufSize - 1] of Byte;
begin
  if AText = 'then
    Exit('');
  TextIn := TStringStream.Create(Base64DecStr(AText));
  TextOut := TStringStream.Create;
  try
    len := TextIn.Size - SizeOf(hdrf) - SizeOf(authf);
    TextIn.ReadBuffer(hdrf, SizeOf(hdrf));

    if (hdrf.FCASig <> C_FCA_Sig) or (hdrf.Flags and $F0 <> $A0) then
      raise Exception.Create('Fehler');

    if hdrf.Flags and $02 <> 0 then
    begin
      writeln(#7'*** Warning: Found zlib compression flag, use t_zlibex to inflate <outfile>');
    end;

    if not(hdrf.Flags and $04 <> 0) then
    begin
      raise Exception.Create('Fehler');
    end;

    hdrk := hdrf;
    UseEAX := odd(hdrf.Flags);
    if UseEAX then
    begin
      if FCA_EAX256_initS(cxe, APassword, hdrk) <> 0 then
        raise Exception.Create('Fehler');
    end
    else
    begin
      if FCA_HMAC256_initS(cxh, APassword, hdrk) <> 0 then
        raise Exception.Create('Fehler');
    end;
    if hdrf.PW_ver <> hdrk.PW_ver then
      raise Exception.Create('Fehler');

    while len > 0 do
    begin
      if len > SizeOf(buf) then
        N := SizeOf(buf)
      else
        N := len;
      TextIn.ReadBuffer(buf, N);
      dec(len, N);
      if UseEAX then
      begin
        if FCA_EAX256_decrypt(cxe, buf, N) <> 0 then
          raise Exception.Create('Fehler');
      end
      else
      begin
        if FCA_HMAC256_decrypt(cxh, buf, N) <> 0 then
          raise Exception.Create('Fehler');
      end;
      TextOut.WriteBuffer(buf, N);
    end;
    if UseEAX then
    begin
      FCA_EAX256_final(cxe, authc);
    end
    else
    begin
      FCA_HMAC256_final(cxh, authc);
    end;
    TextIn.ReadBuffer(authf, SizeOf(authf));
    for I := 0 to 15 do
    begin
      if authf[I] <> authc[I] then
      begin
        raise Exception.Create('Fehler');
      end;
    end;
    Result := TextOut.DataString;
  finally
    TextOut.Free;
    TextIn.Free;
  end;
end;
Achtung: Bin kein Informatiker sondern komme vom Bau.
  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 09:34 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