delphiencodingbase64decodingtms-web-core

Encode String to Base64 using Delphi in TMS Web Core


In FMX, I could use the System.NetEncoding unit for encoding and decoding Base64 Strings in Delphi, but this unit doesn't seem to be available in TMS Web Core:

[Error] uMain_web.pas(29): can't find unit "System.NetEncoding"

What is the TMS Web Core alternative for System.NetEncoding or for decoding/encoding Base64?


Solution

  • Unfortunately, System.NetEncoding isn't available for TMS Web Core.

    In TMS Web Core, you can use window.btoa() and window.atob() though. btoa encodes and atob decodes.

    var
      EncodedString: String;
      DecodedString: String;
    begin
      EncodedString := window.btoa('Shaun Roselt'); // Encode String to Base64
      DecodedString := window.atob('U2hhdW4gUm9zZWx0'); // Decode Base64 String
    end;