Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Base64 Encode/Decode a String
See more Encryption Examples
_LANGUAGE_ example to base-64 encode and decode a string.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
s: string;
strBase64: string;
bd2: TBinData;
decoded: string;
begin
success := False;
bd := TBinData.Create;
s := 'A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump';
success := bd.AppendString(s,'utf-8');
strBase64 := bd.GetEncoded('base64');
WriteLn(strBase64);
// To decode:
bd2 := TBinData.Create;
bd2.AppendEncoded(strBase64,'base64');
decoded := bd2.GetString('utf-8');
WriteLn(decoded);
bd.Free;
bd2.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.