用Delphi6的IdBase64Encoder,IdBase64Decoder控件进行加解密;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, IdCoder3To4, IdBaseComponent, IdCoder, ExtCtrls;
type
TForm1 = class(TForm)
IDE1: TIdBase64Encoder;
IDE2: TIdBase64Decoder;
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Memo2: TMemo;
Label2: TLabel;
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function Fetch(var AInput: string; const ADelim: string = ' '; const ADelete: Boolean = true) : string;
var
iPos: Integer;
begin
if ADelim = #0 then begin
// AnsiPos does not work with #0
iPos := Pos(ADelim, AInput);
end else begin
iPos := AnsiPos(ADelim, AInput);
end;
if iPos = 0 then begin
Result := AInput;
if ADelete then begin
AInput := '';
end;
end else begin
result := Copy(AInput, 1, iPos - 1);
if ADelete then begin
Delete(AInput, 1, iPos + Length(ADelim) - 1);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
posi, posj : integer;
instring, mydata : string;
begin
form1.IDE1.Reset;
form1.IDE1.IgnoreNotification := True;
form1.IDE1.CodeString(memo1.Lines.Text);
mydata := form1.IDE1.CompletedInput;
Fetch(mydata, ';');
memo2.Lines.Text := mydata;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
posi, posj : integer;
instring, mydata : string;
begin
instring := memo1.Lines.Text;
posj := pos('=?big5?b?',lowercase(memo1.Lines.Text));
if posj >0 then
begin
form1.IDE2.Reset;
form1.IDE2.IgnoreNotification := True;
form1.IDE2.CodeString(Copy(instring,posj+9,length(instring)-posj-9));
mydata := form1.IDE2.CompletedInput;
Fetch(mydata, ';');
memo2.Lines.Text := mydata;
end
else
begin
form1.IDE2.Reset;
form1.IDE2.IgnoreNotification := True;
form1.IDE2.CodeString(instring);
mydata := form1.IDE2.CompletedInput;
Fetch(mydata, ';');
memo2.Lines.Text := mydata;
end;
end;
end.