📄 keyfile.pas
字号:
unit KeyFile;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,FGint,FGintRSA;
type
{TSign = (negative, positive);
TFGInt = record
Sign: TSign;
Number: array of int64;
end; }
st32 = string[32];
st64 = string[64];
st128 = string[128];
st255 = string[255];
SysParameter = Record
sign : st64;
HospitalSerialNumber :st128;
MagneticFiled : st128;
TimeLimit : st128;
end;
TForm_KeyFile = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit_HospitalSerialNumber: TEdit;
Label3: TLabel;
Edit_MagneticFiled: TEdit;
Label4: TLabel;
Edit_Year: TEdit;
Edit_Month: TEdit;
Edit_Data: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Button_Encrypt: TButton;
Button_Decrypt: TButton;
procedure Button_EncryptClick(Sender: TObject);
procedure Button_DecryptClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{procedure RSAEncrypt(p: string; var exp, Modb: TFGInt; var e: string); far;external 'RSA.DLL';
procedure RSADecrypt(e: string; var exp, Modb, d_p, d_q, p, q: TFGInt; var d: string);far; external 'RSA.DLL' ;
procedure Base10StringToFGInt(Base10: string; var FGInt: TFGInt);far; external 'RSA.DLL' ;
procedure ConvertBase256StringToHexString(str256: string; var HexStr: string);far;external 'RSA.DLL';
procedure ConvertHexStringToBase256String(HexStr: string; var str256: string); far; external 'RSA.DLL';
procedure FGIntDestroy(var FGInt: TFGInt); far ; external 'RSA.DLL'; }
Const
coSize = sizeof(SysParameter);
var
Form_KeyFile: TForm_KeyFile;
e,n,nilgint,d : TFgint;
implementation
{$R *.dfm}
procedure TForm_KeyFile.Button_EncryptClick(Sender: TObject);
var
timeLimit : String;
tempString,tempString1 : String;
fileName : String;
F : File;
bytesWritten : integer;
SysParameter_1 : SysParameter;
begin
//e :65537;
//n :274568411260517817960062277601;
//d :212517466104128789225285720729
//dp:43631099
//dq:109294009628547398819
//p: 260162983
//q: 1055370783707987457847
Base10StringToFGInt('65537',e);
Base10StringToFGInt('274568411260517817960062277601',n);
RSAEncrypt(Edit_HospitalSerialNumber.Text,e,n,tempString);
ConvertBase256StringToHexString(tempString,tempString1);
SysParameter_1.hospitalSerialNumber := tempString1;
tempString := '';
tempString1 := '';
RSAEncrypt(Edit_MagneticFiled.Text,e,n,tempString);
ConvertBase256StringToHexString(tempString,tempString1);
SysParameter_1.MagneticFiled := tempString1;
tempString := '';
tempString1 := '';
timeLimit := Edit_Year.Text + Edit_Month.Text + Edit_Data.Text;
RSAEncrypt(timeLimit,e,n,tempString);
ConvertBase256StringToHexString(tempString,tempString1);
SysParameter_1.TimeLimit := tempString1;
FGIntDestroy(e);
FGIntDestroy(n);
FileName := ExtractFilePath(Application.ExeName) + 'Key.dll';
AssignFile(F,FileName);
reWrite(F,1);
blockWrite(F,SysParameter_1,coSize,bytesWritten);
closefile(F);
end;
procedure TForm_KeyFile.Button_DecryptClick(Sender: TObject);
var
tempString,b64 : string;
F : File;
fileName : string;
bytesRead : integer;
SysParameter_1 : SysParameter;
begin
FileName := ExtractFilePath(Application.ExeName) + 'Key.dll';
AssignFile(F,FileName);
reset(F,2);
blockread(F,SysParameter_1,coSize,bytesRead);
closeFile(F);
Base10StringToFGInt('274568411260517817960062277601',n);
Base10StringToFGInt('212517466104128789225285720729',d);
ConvertHexStringToBase256String(SysParameter_1.HospitalSerialNumber,tempString);
RSADecrypt(TempString, d, n, nilgint, nilgint, nilgint, nilgint, b64);
Edit_HospitalSerialNumber.Text := b64;
b64 := '';
tempString := '';
ConvertHexStringToBase256String(SysParameter_1.MagneticFiled,tempString);
RSADecrypt(TempString, d, n, nilgint, nilgint, nilgint, nilgint, b64);
Edit_MagneticFiled.Text := b64;
FGIntDestroy(n);
FGIntDestroy(d);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -