Base64EncodeToStr - cCharTranslate

Creates a base 64 encoded String from a binary memory buffer

Type: Function

Return Data Type: String

Parameters: Pointer pBinaryData Integer iBinaryLen

ParameterDescription
pBinaryDataThe address of the binary data
iBinaryLenThe length of the binary data


Return Value

The data is encoded by calling Base64Encode and returned as a DataFlex string


Syntax
Function Base64EncodeToStr Pointer pBinaryData Integer iBinaryLen Returns String

Call: Get Base64EncodeToStr pBinaryData iBinaryLen to StringVariable


Description

Base64EncodeToStr creates a base 64 encoded DataFlex String from a binary memory buffer.

Base64EncodeToVariantStr Base64EncodeToVariantStr creates a base 64 encoded Variant String from a binary memory buffer.
Base64Encode converts binary data to base64 data.

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

This is often paired with Base64DecodeFromStr.

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

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