Binary to Base64 (Delphi)

南楼画角 提交于 2019-11-26 09:02:52

问题


how can i get content of an exe file and convert it into Base64 encoding ?

Edit

I use D2010 and i want to know how is it possible exactly ?

  • open an exe file
  • convert its content into base64

回答1:


In Delphi 2009/2010/XE there is unit EncdDecd.pas (Soap.EncdDecd.pas for Delphi XE2) containing the functions EncodeBase64 and DecodeBase64. You can load the exe file into a memorystream and then call EncodeBase64.

function EncodeFile(const FileName: string): AnsiString;
var
  stream: TMemoryStream;
begin
  stream := TMemoryStream.Create;
  try
    stream.LoadFromFile(Filename);
    result := EncodeBase64(stream.Memory, stream.Size);
  finally
    stream.Free;
  end;
end;



回答2:


In ancient Delphi versions, you can use synapse (link here)

Just put synacode.pas in your uses e call EncodeBase64/EncodeBase64.

Cheers



来源:https://stackoverflow.com/questions/5795263/binary-to-base64-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!