Sample code for 30+ languages & platforms
Lazarus Pascal

Decode Base64

Demonstrates how to decode base64.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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;
  password: string;

begin
  success := False;

  bd := TBinData.Create;

  //  Append a base64 string to bd.
  success := bd.AppendEncoded('c2VjcmV0','base64');

  //  The bd now contains the decoded bytes.
  //  Let's say it was a password string..
  password := bd.GetString('utf-8');

  //  Decodes to "secret".
  WriteLn('password = ' + password);


  bd.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.