Base64Decoder()

Syntax

Result = Base64Decoder(*InputBuffer, InputSize, *OutputBuffer, OutputSize)
Description
Decodes the specified Base64 encoded buffer.

Parameters

*InputBuffer The buffer containing the encoded data.
InputSize The size of the input buffer.
*OutputBuffer The output buffer where the plain data will be copied.
OutputSize The size of the output buffer.

The output buffer can be up to 33% smaller than the input buffer, with a minimum size of 64 bytes. It's recommended to get a slightly larger buffer, like 30% smaller to avoid overflows.

Return value

Returns the length of the decoded data in bytes.

Example

  Example$ = "This is a test string!" 
  Decoded$ = Space(1024) 
  Encoded$ = Space(1024) 
    
  Debug Base64Encoder(@Example$, StringByteLength(Example$), @Encoded$, 1024)
  Debug Encoded$ 
    
  Debug Base64Decoder(@Encoded$, StringByteLength(Encoded$), @Decoded$, 1024)
  Debug Decoded$

Example: Encoding & Decoding from a DataSection

  DataSection
    Test:
    Data.a $00, $01, $02, $03, $04, $05, $06, $07
    Data.a $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
    TestEnd:
  EndDataSection
  
  Size = (?TestEnd - ?Test) * 1.35
  If Size < 64
    Size = 64
  EndIf
  
  *EncodeBuffer = AllocateMemory(Size)
  Size = Base64Encoder(?Test, ?TestEnd - ?Test, *EncodeBuffer, MemorySize(*EncodeBuffer))
  Encoded$ = PeekS(*EncodeBuffer, Size, #PB_Ascii)
  Debug Encoded$
  
  *DecodeBuffer = AllocateMemory(Size)
  Size = PokeS(*EncodeBuffer, Encoded$, StringByteLength(Encoded$, #PB_Ascii), #PB_Ascii|#PB_String_NoZero)
  Size = Base64Decoder(*EncodeBuffer, Size, *DecodeBuffer, MemorySize(*DecodeBuffer))
  ShowMemoryViewer(*DecodeBuffer, Size)

See Also

Base64Encoder()

Supported OS

All

<- AddFingerprintBuffer() - Cipher Index - Base64Encoder() ->