Base64DecodeFromStr - cCharTranslate

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

Type: Function

Return Data Type: Pointer

Parameters: String sBase64 Integer ByRef iBinaryLen

ParameterDescription
sBase64String as Base64
iBinaryLen (ByRef)Returns the length of the binary buffer


Return Value

The buffer address of the decoded string


Syntax
Function Base64DecodeFromStr String sBase64 Integer ByRef iBinaryLen Returns Pointer

Call: 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()