Autor Beitrag
iea
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 26.06.08 17:17 
Hi,

dies ist mein erster Beitrag aber ich komm einfach nicht weiter.

Ich habe ein Delphi Programm, welches mir einen String Ver- und Entschlüsselt. Leider is das Ganze eine Form.

Ich möchte wenn möglich das ganze über die Console benutzen.

crypt.exe /(en)decrypt /key1 /key2 /string
Ausgabe = String


Ich würde mich freuen wenn es sich jemand mal anschaeun könnte, der Quelltext ist sehr kurz aber für mich leider Chinesich =)

Für eure Hilfe wär ich euch sehr dankbar ----
Einloggen, um Attachments anzusehen!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 17:22 
Moin und :welcome: im Forum!

user profile iconiea hat folgendes geschrieben:
Ich habe ein Delphi Programm, welches mir einen String Ver- und Entschlüsselt. Leider is das Ganze eine Form.
[...]
Ich würde mich freuen wenn es sich jemand mal anschaeun könnte, der Quelltext ist sehr kurz aber für mich leider Chinesich =)
Hm :? ist denn der Code nicht von dir, oder warum ist das chinesisch für dich? :nixweiss:

user profile iconiea hat folgendes geschrieben:
Ich möchte wenn möglich das ganze über die Console benutzen.
Wo genau ist denn dein Problem, das hast du dabei noch gar nicht verraten. ;)

user profile iconiea hat folgendes geschrieben:
Für eure Hilfe wär ich euch sehr dankbar
Wir helfen dir gerne - dabei deine Probleme zu lösen. :D Ein erster Ansatz wäre, wenn du uns nicht einfach das Projekt vor die Füße wirfst, sondern die entsprechenden Stellen im Code direkt hier im Beitrag aufzeigst und dazu sagst, was nicht klappt oder wo der Fehler auftritt. :idea:

Zum Thema Kommandozeilenparameter haben wir auch einen FAQ-Beitrag. :les: :think: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Do 26.06.08 17:24 
Dann darfst du keine Formularanwendung anlegen, sondern eine Konsolenanwendung...
-> Neues Projekt -> Konsolenanwendung
iea Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 26.06.08 17:30 
Danke für die Super schnellen Antworten.

Nein der Quellcode ist nicht von mir, ich bin froh das ich die beiden Quelltext Dateien in ein Borland Delphi Projekt importieren konnte =)

Also eine Consolenanwendung habe ich angelegt. Und hier ist mal der eigentlich Quelltext... sry für die RAR Datei mit dem ganzen Projekt.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
unit uMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmMain = class(TForm)
    boxKey: TEdit;
    boxIV: TEdit;
    boxPlainTextIn: TEdit;
    boxCipherTextOut: TEdit;
    boxCipherTextIn: TEdit;
    boxPlainTextOut: TEdit;
    lblKey: TLabel;
    lblIV: TLabel;
    lblPlainTextOut: TLabel;
    lblCipherTextOut: TLabel;
    lblCipherTextIn: TLabel;
    lblPlainTextIn: TLabel;
    btnEncrypt: TButton;
    btnDecrypt: TButton;
    procedure btnEncryptClick(Sender: TObject);
    procedure btnDecryptClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

uses
  DCPcrypt2, DCPrijndael, DCPbase64;

// Some constants that are dependant on the cipher being used
// Assuming MCRYPT_RIJNDAEL_128 (i.e., 128bit blocksize, 256bit keysize)
const
  KeySize = 32; // 32 bytes = 256 bits
  BlockSize = 16; // 16 bytes = 128 bits



{$R *.dfm}

// Pad a string with zeros so that it is a multiple of size
function PadWithZeros(const str : string; size : integer) : string;
var
  origsize, i : integer;
begin
  Result := str;
  origsize := Length(Result);
  if ((origsize mod size) <> 0) or (origsize = 0) then
  begin
    SetLength(Result,((origsize div size)+1)*size);
    for i := origsize+1 to Length(Result) do
      Result[i] := #0;
  end;
end;

// Encrypt a string and return the Base64 encoded result
procedure TfrmMain.btnEncryptClick(Sender: TObject);
var
  Cipher : TDCP_rijndael;
  Data, Key, IV : string;
begin
  // Pad Key, IV and Data with zeros as appropriate
  Key := PadWithZeros(boxKey.Text,KeySize);
  IV := PadWithZeros(boxIV.Text,BlockSize);
  Data := PadWithZeros(boxPlainTextIn.Text,BlockSize);
  // Create the cipher and initialise according to the key length
  Cipher := TDCP_rijndael.Create(Self);
  if Length(boxKey.Text) <= 16 then
    Cipher.Init(Key[1],128,@IV[1])
  else if Length(boxKey.Text) <= 24 then
    Cipher.Init(Key[1],192,@IV[1])
  else
    Cipher.Init(Key[1],256,@IV[1]);
  // Encrypt the data
  Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
  // Free the cipher and clear sensitive information
  Cipher.Free;
  FillChar(Key[1],Length(Key),0);
  // Display the Base64 encoded result
  boxCipherTextOut.Text := Base64EncodeStr(Data);
end;

procedure TfrmMain.btnDecryptClick(Sender: TObject);
var
  Cipher : TDCP_rijndael;
  Data, Key, IV : string;
begin
  // Pad Key and IV with zeros as appropriate
  Key := PadWithZeros(boxKey.Text,KeySize);
  IV := PadWithZeros(boxIV.Text,BlockSize);
  // Decode the Base64 encoded string
  Data := Base64DecodeStr(boxCipherTextIn.Text);
  // Create the cipher and initialise according to the key length
  Cipher := TDCP_rijndael.Create(Self);
  if Length(boxKey.Text) <= 16 then
    Cipher.Init(Key[1],128,@IV[1])
  else if Length(boxKey.Text) <= 24 then
    Cipher.Init(Key[1],192,@IV[1])
  else
    Cipher.Init(Key[1],256,@IV[1]);
  // Decrypt the data
  Cipher.DecryptCBC(Data[1],Data[1],Length(Data));
  // Free the cipher and clear sensitive information
  Cipher.Free;
  FillChar(Key[1],Length(Key),0);
  // Display the result
  boxPlainTextOut.Text := Data;
end;

end.



Wenn ich mich nicht Irre kann ich die Bibliotheken so in eine Consolen Anwendung übernehmen. Nur die Zeilen die den eingegeben String aus der Form holen muss ich ja jetzt über einen Parameter einlesen.

Hier z.B.:

ausblenden Delphi-Quelltext
1:
Key := PadWithZeros(boxKey.Text,KeySize);					




Danke nochmal für die schnelle Antwort.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 17:34 
Moin!

user profile iconiea hat folgendes geschrieben:
Nein der Quellcode ist nicht von mir, ich bin froh das ich die beiden Quelltext Dateien in ein Borland Delphi Projekt importieren konnte =)
Ah, OK. Aber du hast schon vor, dich mit Delphi zu beschäftigen, um zu lernen, wie man das Problem lösen kann? ;) Oder geht es nur darum, jemanden zu finden, der dir den Code zusammenschraubt? (in diesem Fall verschiebe ich deine Anfrage gerne in die Sparte Job-Angebote). :nixweiss:

user profile iconiea hat folgendes geschrieben:
Wenn ich mich nicht Irre kann ich die Bibliotheken so in eine Consolen Anwendung übernehmen. Nur die Zeilen die den eingegeben String aus der Form holen muss ich ja jetzt über einen Parameter einlesen.

Hier z.B.:

ausblenden Delphi-Quelltext
1:
Key := PadWithZeros(boxKey.Text,KeySize);					
Hast du mal in den FAQ-Beitrag reingesehen?

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
iea Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 26.06.08 17:40 
Naja wenns jemand schnell machen kann hätte ich natürlich nichts dagegen ... aber ich investiere auch gerne Zeit für meine eigenen Projekte ;)

Mein erste eigentlich Frage ist wie ich Parameter an meine Konsolenapplikation übergeben kann und wich ich diese in einer Variable speichern kann.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 17:43 
user profile iconiea hat folgendes geschrieben:
Mein erste eigentlich Frage ist wie ich Parameter an meine Konsolenapplikation übergeben kann und wich ich diese in einer Variable speichern kann.
user profile iconNarses hat folgendes geschrieben:
Hast du mal in den FAQ-Beitrag reingesehen?

_________________
There are 10 types of people - those who understand binary and those who don´t.
iea Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 26.06.08 18:27 
ok hab einen Ansatz =)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
program Project1;

{$APPTYPE CONSOLE}

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DCPcrypt2, DCPrijndael, DCPbase64;

  var
  Cipher : TDCP_rijndael;
  Data, Key, IV, Test : string;


begin
  if ParamStr(1) = '' then
  begin
    Writeln('No Parameter defined');
  end
  else
  begin
  Writeln(ParamStr(1));



  Key := 'test';
  IV := 'test';
  Data := 'test';

  Cipher := TDCP_rijndael.Create(self);
  Cipher.Init(Key[1],128,@IV[1]);
  Cipher.EncryptCBC(Data[1],Data[1],Length(Data))
  


end;



Bekomme aber in folgender Zeile einen Fehler ...

ausblenden Delphi-Quelltext
1:
 Cipher := TDCP_rijndael.Create(self);					



Folgende Meldung :

[Fehler] Project1.dpr(29): E2010 Inkompatible Typen: 'TComponent' und 'string'
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 26.06.08 18:59 
das liegt daran, das dein self früher mal die Form war, die jetzt aber nicht mehr da ist...

Ähh... Jetzt steh ich aufm Schlauch... was kommt dann da rein, wenn nicht die Form?
Application? Stammt ja auch von TComponent ab...

Aber geht das?

_________________
1405006117752879898543142606244511569936384000000000.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 26.06.08 19:06 
Moin!

user profile iconWolle92 hat folgendes geschrieben:
Ähh... Jetzt steh ich aufm Schlauch... was kommt dann da rein, wenn nicht die Form?
Application? Stammt ja auch von TComponent ab...
Komponenten erzeugt man dynamisch am besten so, wenn man kein Formular hat (oder sich selbst um die Freigabe kümmern will/muss):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
Button := TButton.Create(NIL);
try
  //...
finally
  Button.Free;
end;
cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
iea Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Do 26.06.08 19:38 
Hi

ich hab es geschafft zumindest zu 99% =)

Doch wenn ich den String verschlüssel kommt ein anderer String rauß.

String = Test

Original: M3ctMD1ZW80QKKTBmkOFiQ==
Meiner: 0kalgk5wDf4DIXwHWaVb1w==

Fällt euch noch ein Fehler auf?

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
program Project1;

{$APPTYPE CONSOLE}

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DCPcrypt2, DCPrijndael, DCPbase64;

  var
  Cipher : TDCP_rijndael;
  Data, Key, IV, Test : string;

  const
  KeySize = 32;
  BlockSize = 16;

function PadWithZeros(const str : string; size : integer) : string;
var
  origsize, i : integer;
begin
  Result := str;
  origsize := Length(Result);
  if ((origsize mod size) <> 0) or (origsize = 0) then
  begin
    SetLength(Result,((origsize div size)+1)*size);
    for i := origsize+1 to Length(Result) do
      Result[i] := #0;
  end;
end;

begin

  if ParamStr(1) = '' then
  begin
    Writeln('No Parameter defined');
  end
  else
  begin

    Test := 'Test';
               Writeln(Test);
    Key := PadWithZeros(Test,KeySize);
    IV := PadWithZeros(Test,BlockSize);
    Data := PadWithZeros(Test,BlockSize);


    Cipher := TDCP_rijndael.Create(NIL);

    if Length(Key) <= 16 then
      Cipher.Init(Key[1],128,@IV[1])
    else if Length(Key) <= 24 then
      Cipher.Init(Key[1],192,@IV[1])
    else
      Cipher.Init(Key[1],256,@IV[1]);
      Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
      Cipher.Free;
      FillChar(Key[1],Length(Key),0);
      Test := Base64EncodeStr(Data);
      Writeln(Base64EncodeStr(Data));
    end;

  readln;    //getch()
end.