(PureBasic) Base64 Encode/Decode a String
PureBasic example to base-64 encode and decode a string.
IncludeFile "CkBinData.pb"
Procedure ChilkatExample()
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
s.s = "A friend called me up the other day and talked about investing in a dot-com that sells lobsters. Internet lobsters. Where will this end? --Donald Trump"
success.i = CkBinData::ckAppendString(bd,s,"utf-8")
strBase64.s = CkBinData::ckGetEncoded(bd,"base64")
Debug strBase64
; To decode:
bd2.i = CkBinData::ckCreate()
If bd2.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkBinData::ckAppendEncoded(bd2,strBase64,"base64")
decoded.s = CkBinData::ckGetString(bd2,"utf-8")
Debug decoded
CkBinData::ckDispose(bd)
CkBinData::ckDispose(bd2)
ProcedureReturn
EndProcedure
|