Skip to content

Commit 94d063d

Browse files
committed
Add SHA1, SHA256, SHA512
1 parent 119e544 commit 94d063d

File tree

8 files changed

+78
-2
lines changed

8 files changed

+78
-2
lines changed

RSAOpenSSL.dcu

1.1 KB
Binary file not shown.

RSAOpenSSL.pas

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ TRSAOpenSSL = class
3434
procedure LoadSSL;
3535
function LoadPrivateKeyFromString(KeyFile: string): pEVP_PKEY;
3636

37-
38-
3937
public
4038
{ Public declarations }
4139
constructor Create(aPathToPublickKey, aPathToPrivateKey: string); overload;
@@ -47,6 +45,8 @@ TRSAOpenSSL = class
4745
function SHA1_base64(AData: string): string;
4846
function SHA1_Sign_PK(AData: string): string;
4947
function SHA1(AData: string): string;
48+
function SHA256(AData: string): string;
49+
function SHA512(AData: string): string;
5050
protected
5151

5252
end;
@@ -503,6 +503,46 @@ function TRSAOpenSSL.SHA1(AData: string): string;
503503
result := StrPas(inbuf);
504504
end;
505505

506+
function TRSAOpenSSL.SHA256(AData: string): string;
507+
var
508+
Len: cardinal;
509+
mdctx: EVP_MD_CTX;
510+
inbuf, outbuf: array [0..1023] of char;
511+
key: pEVP_PKEY;
512+
begin
513+
StrPCopy(inbuf, AData);
514+
LoadSSL;
515+
516+
EVP_DigestInit(@mdctx, EVP_sha256());
517+
EVP_DigestUpdate(@mdctx, @inbuf, StrLen(inbuf));
518+
EVP_DigestFinal(@mdctx, @outbuf, Len);
519+
520+
FreeSSL;
521+
BinToHex(outbuf, inbuf,Len);
522+
inbuf[2*Len]:=#0;
523+
result := StrPas(inbuf);
524+
end;
525+
526+
function TRSAOpenSSL.SHA512(AData: string): string;
527+
var
528+
Len: cardinal;
529+
mdctx: EVP_MD_CTX;
530+
inbuf, outbuf: array [0..1023] of char;
531+
key: pEVP_PKEY;
532+
begin
533+
StrPCopy(inbuf, AData);
534+
LoadSSL;
535+
536+
EVP_DigestInit(@mdctx, EVP_sha512());
537+
EVP_DigestUpdate(@mdctx, @inbuf, StrLen(inbuf));
538+
EVP_DigestFinal(@mdctx, @outbuf, Len);
539+
540+
FreeSSL;
541+
BinToHex(outbuf, inbuf,Len);
542+
inbuf[2*Len]:=#0;
543+
result := StrPas(inbuf);
544+
end;
545+
506546
function TRSAOpenSSL.SHA1_Sign_PK(AData: string): string;
507547
var
508548
Len: cardinal;

RSAUtil.exe

512 Bytes
Binary file not shown.

Unit1.dcu

677 Bytes
Binary file not shown.

Unit1.dfm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ object Form1: TForm1
6969
TabOrder = 4
7070
OnClick = Button5Click
7171
end
72+
object Button6: TButton
73+
Left = 8
74+
Top = 232
75+
Width = 121
76+
Height = 25
77+
Caption = 'SHA256'
78+
TabOrder = 5
79+
OnClick = Button6Click
80+
end
81+
object Button7: TButton
82+
Left = 8
83+
Top = 272
84+
Width = 121
85+
Height = 25
86+
Caption = 'SHA512'
87+
TabOrder = 6
88+
OnClick = Button7Click
89+
end
7290
end
7391
object Panel2: TPanel
7492
Left = 0

Unit1.pas

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ TForm1 = class(TForm)
2323
Button3: TButton;
2424
Button4: TButton;
2525
Button5: TButton;
26+
Button6: TButton;
27+
Button7: TButton;
2628
procedure FormCreate(Sender: TObject);
2729
procedure Button1Click(Sender: TObject);
2830
procedure Button2Click(Sender: TObject);
2931
procedure Button3Click(Sender: TObject);
3032
procedure Button4Click(Sender: TObject);
3133
procedure Button5Click(Sender: TObject);
34+
procedure Button6Click(Sender: TObject);
35+
procedure Button7Click(Sender: TObject);
3236
private
3337
{ Private declarations }
3438
fRSAOpenSSL : TRSAOpenSSL;
@@ -106,4 +110,14 @@ procedure TForm1.Button5Click(Sender: TObject);
106110
Memo3.Text := fRSAOpenSSL.SHA1(Memo1.Text);
107111
end;
108112

113+
procedure TForm1.Button6Click(Sender: TObject);
114+
begin
115+
Memo3.Text := fRSAOpenSSL.SHA256(Memo1.Text);
116+
end;
117+
118+
procedure TForm1.Button7Click(Sender: TObject);
119+
begin
120+
Memo3.Text := fRSAOpenSSL.SHA512(Memo1.Text);
121+
end;
122+
109123
end.

libeay32.dcu

130 Bytes
Binary file not shown.

libeay32.pas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,8 @@ function EVP_md2: pEVP_MD; cdecl;
983983
function EVP_md5: pEVP_MD; cdecl;
984984
function EVP_sha: pEVP_MD; cdecl;
985985
function EVP_sha1: pEVP_MD; cdecl;
986+
function EVP_sha256: pEVP_MD; cdecl;
987+
function EVP_sha512: pEVP_MD; cdecl;
986988
function EVP_dss: pEVP_MD; cdecl;
987989
function EVP_dss1: pEVP_MD; cdecl;
988990
function EVP_mdc2: pEVP_MD; cdecl;
@@ -1662,6 +1664,8 @@ function EVP_md2; external LIBEAY_DLL_NAME;
16621664
function EVP_md5; external LIBEAY_DLL_NAME;
16631665
function EVP_sha; external LIBEAY_DLL_NAME;
16641666
function EVP_sha1; external LIBEAY_DLL_NAME;
1667+
function EVP_sha256; external LIBEAY_DLL_NAME;
1668+
function EVP_sha512; external LIBEAY_DLL_NAME;
16651669
function EVP_dss; external LIBEAY_DLL_NAME;
16661670
function EVP_dss1; external LIBEAY_DLL_NAME;
16671671
function EVP_mdc2; external LIBEAY_DLL_NAME;

0 commit comments

Comments
 (0)