forked from ddlencemc/RSA-via-OpenSSL-libeay32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.pas
123 lines (103 loc) · 2.87 KB
/
Unit1.pas
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
121
122
123
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, RsaOpenSSL;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
private
{ Private declarations }
fRSAOpenSSL : TRSAOpenSSL;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
aPathToPublickKey, aPathToPrivateKey: string;
begin
aPathToPublickKey := 'public.pem';
aPathToPrivateKey := 'private.pem';
fRSAOpenSSL := TRSAOpenSSL.Create(aPathToPublickKey, aPathToPrivateKey);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
aRSAData: TRSAData;
begin
aRSAData.DecryptedData := Memo1.Text;
fRSAOpenSSL.PublickEncrypt(aRSAData);
if aRSAData.ErrorResult = 0 then
memo2.Lines.Text := aRSAData.CryptedData;
memo4.Lines.Add(aRSAData.ErrorMessage);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
aRSAData: TRSAData;
begin
aRSAData.CryptedData := Memo2.Text;
fRSAOpenSSL.PrivateDecrypt(aRSAData);
if aRSAData.ErrorResult = 0 then
memo3.Lines.Text := aRSAData.DecryptedData;
memo4.Lines.Add(aRSAData.ErrorMessage);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
aRSAData: TRSAData;
begin
aRSAData.DecryptedData := Memo1.Text;
fRSAOpenSSL.PrivateEncrypt(aRSAData);
if aRSAData.ErrorResult = 0 then
memo2.Lines.Text := aRSAData.CryptedData;
memo4.Lines.Add(aRSAData.ErrorMessage);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
aRSAData: TRSAData;
begin
aRSAData.CryptedData := Memo2.Text;
fRSAOpenSSL.PublicDecrypt(aRSAData);
if aRSAData.ErrorResult = 0 then
memo3.Lines.Text := aRSAData.DecryptedData;
memo4.Lines.Add(aRSAData.ErrorMessage);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Memo3.Text := fRSAOpenSSL.SHA1(Memo1.Text);
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
Memo3.Text := fRSAOpenSSL.SHA256(Memo1.Text);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
Memo3.Text := fRSAOpenSSL.SHA512(Memo1.Text);
end;
end.