English 中文(简体)
• 如何将任何类型的密码存档到底64,然后用Lazaus/Delphi将其编码为档案?
原标题:How to encode file of any type into base64 string and then decode it into file again using Lazarus/Delphi?

Can you tell me how can I do that? Is there any Freepascal unit that can do this for me? I need that so my program can store binary data in it s XML-based fileformat.

问题回答

http://www.freepascal.org/docs-html/fcl/base64/index.html TBase64DecodingStream

http://fpc-docs.gorilla3d.com/built-in-units/base64/tbase64encodingstream”

program demo;

uses Classes, base64;

var
  DecodedStream: TStringStream;
  EncodedStream: TStringStream;
  Encoder: TBase64EncodingStream;
  Output: string;
begin
  DecodedStream := TStringStream.Create( Hello World! );
  EncodedStream := TStringStream.Create(  );
  Encoder       := TBase64EncodingStream.Create(EncodedStream);
  Encoder.CopyFrom(DecodedStream, DecodedStream.Size);

  Output := EncodedStream.DataString;
  { Outputs  SGVsbG8gV29ybGQh  }
  WriteLn(Output);

  DecodedStream.Free;
  EncodedStream.Free;
  Encoder.Free;
end.

http://fpc-docs.gorilla3d.com/built-in-units/base64/tbase64decodingstream”

program demo;

uses Classes, base64;

var
  DecodedStream: TStringStream;
  EncodedStream: TStringStream;
  Decoder: TBase64DecodingStream;
  Output: string;
begin
  EncodedStream := TStringStream.Create( SGVsbG8gV29ybGQh );
  DecodedStream := TStringStream.Create(  );
  Decoder       := TBase64DecodingStream.Create(EncodedStream);
  DecodedStream.CopyFrom(Decoder, Decoder.Size);

  Output := DecodedStream.DataString;
  { Outputs  Hello World!  }
  WriteLn(Output);

  DecodedStream.Free;
  EncodedStream.Free;
  Decoder.Free;
end.

http://www.free Pascal.org/docs-html/fcl/ Base 64en.2/string Base64.html

Uses Base64;
var 
   s : AnsiString;
Begin
  s:=EncodeStringBase64( Hello world! );
  Writeln( Encoded :  ,s);
  s:=DecodeStringBase64(s);
  Writeln( Decoded again :  ,s);    
end.




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签