Base64Encoder()

Syntax

Result$ = Base64Encoder(*InputBuffer, InputSize [, Flags])
Description
Encodes the specified buffer using the Base64 algorithm. This is widely used in e-mail programs but can be useful for any other programs which need an ASCII only (7 bit, only from 32 to 127 characters) encoding for raw binary files.

Parameters

*InputBuffer The buffer containing the plain data.
InputSize The size of the input buffer.
Flags (optional) It can be a combination of the following values:
  #PB_Cipher_NoPadding: it will not insert additional '=' at the end of the encoded buffer to pad it to 3 bytes boundary.
  #PB_Cipher_URL      : it will use a slightly different encoding, mainly used in URL. The usual '+' and '/' encoded characters
                        will be respectively encoded to '-' and '_'

Return value

Returns the encoded data as a string.

Example

  String$ = "This is a test string!"
  
  ; Encoding an UTF-8 string
  *Text = UTF8(String$)
  Encoded$ = Base64Encoder(*Text, StringByteLength(String$, #PB_UTF8))
  Debug "Encoded: " + Encoded$
  
  *DecodedBuffer = AllocateMemory(1024)
  Base64Decoder(Encoded$, *DecodedBuffer, 1024)
  Debug "Decoded: '" + PeekS(*DecodedBuffer, -1, #PB_UTF8) + "'"
  
  FreeMemory(*Text)
  FreeMemory(*DecodedBuffer)

See Also

Base64Decoder(), Base64DecoderBuffer(), Base64EncoderBuffer()

Supported OS

All

<- Base64DecoderBuffer() - Cipher Index - Base64EncoderBuffer() ->