Skip to content

Base64DecodeFromStr - cCharTranslate

Decodes a base 64 encoded string and places it in a newly created memory buffer

Type: Function
Return Data Type: Pointer

Parameters

Parameter Type Description
sBase64 String String as Base64
ByRef iBinaryLen Integer Returns the length of the binary buffer

Syntax

Function Base64DecodeFromStr String sBase64 ByRef Integer iBinaryLen Returns Pointer

Call Example

Get Base64DecodeFromStr sBase64 iBinaryLen to PointerVariable

Description

Base64DecodeFromStr decodes a base 64 encoded DataFlex String and places it in a newly created memory buffer.

You are responsible for eventually disposing of the newly created memory buffer.

This is often paired with Base64EncodeToStr.

Use Windows.pkg
Use cCharTranslate.pkg

Object oCharTranslate is a cCharTranslate
End_Object

Procedure TestBase64EncodeStr
    Pointer aBinary aBinary2
    Integer iVoid iLen iLen2
    String sVar sData sData2

    // aBinary could be any binary data of length iLen
    Move "Pretend this is actually binary data" to sData
    Move (AddressOf(sData)) to aBinary
    Move (SizeOfString(sData)) to iLen

    // base64Encode to string
    Get Base64EncodeToStr of oCharTranslate aBinary iLen to sVar

    // base64 decode from string 
    Get Base64DecodeFromStr of oCharTranslate sVar (&iLen2) to aBinary2
    If (iLen<>iLen2 or MemCompare(aBinary,aBinary2,iLen2)) Begin
        Send Info_Box "Test Failed"
    End

    Move (Free(aBinary2)) to iVoid
End_Procedure

Send TestBase64EncodeStr

See Also

Base64EncodeToStr | Base64EncodeToVariantStr | Base64DecodeFromVariantStr | Base64Encode | Base64Decode | Free()

Return Value

The buffer address of the decoded string