base64加解密

  • A+
所属分类:[开发技巧]

代码效果如下

按钮1是将edit1内容加密,并存入text文件中,按钮2是在text文件中读取加密后的内容,并解密。

unit Unit1;

interface

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

type
TForm1 = class(TForm)
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
btn1: TButton;
btn2: TButton;
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
t:Text;
f:string;
implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
edt2.Text:=EncodeString(edt1.Text);
if FileExists(f) then
begin
AssignFile(t,f);
end
else
begin
AssignFile(t,f);
Rewrite(t);
end;
Append(t);
Writeln(t,edt2.text);
CloseFile(t);
end;

procedure TForm1.btn2Click(Sender: TObject);
var
s:string;
begin
if FileExists(f) then
begin
AssignFile(t,f);
Reset(t);
while not Eof(t) do
Readln(t,s);
edt3.Text:=DecodeString(s);
end;
CloseFile(t);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
f:=ExtractFilePath(ParamStr(0))+'text.txt';
end;

end.


  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: