Skip to main content
Inspiring
March 21, 2008
Question

Base64 to string

  • March 21, 2008
  • 6 replies
  • 1126 views
Hi,

I have a text that has been converted using ToBase64 and I am trying to convert it back to string. I am trying to use BinaryDecode with Base64 encoding to convert it but it keeps telling me that text must be valid binary object?
Please help!
This topic has been closed for replies.

6 replies

TiGGiAuthor
Inspiring
March 24, 2008
cfSearching

Text was converted using toBase64 now I need to convert it back to text again.

I used toString(ToBinary(base64text)) to convert it back to text. My question was since CF documentation recommends using BinaryDecode instead of ToBinary, how do I use BinaryDecode? I was not able to figure it out.
Participating Frequently
March 24, 2008
<cfset myText = "This is my Unicode Text ğĞüÜıİşŞöÖçÇ">
<cfdump var="#myText#">
<br />
<cfset mybase64 = toBase64(myText)>
<cfdump var="#mybase64#">
<br />
<cfset myTextBack = toString(ToBinary(mybase64))>
<cfdump var="#myTextBack#">

This works.

Same thing with BineryDecode

<cfset myTextBack = toString(BinaryDecode((mybase64),'Base64'))>

BKBK
Community Expert
Community Expert
March 21, 2008
TiGGi wrote:
I have a text that has been converted using ToBase64 and I am trying to convert it back to string. I am trying to use BinaryDecode with Base64 encoding

Use BinaryEncode() not BinaryDecode()
stringData = BinaryEncode(toBinary(yourBase64Data), "base64")


Inspiring
March 21, 2008
TiGGi wrote:
> I have a text that has been converted using ToBase64 and I am trying to convert it back to string.

Your question is confusing. Base64 text is a string. Do you mean you want to convert a base64 string back into binary? As BKBK mentioned, BinaryEncode will convert binary data to base64 and BinaryDecode will convert base64 back into binary. Do you understand the difference?
Participating Frequently
March 21, 2008
What I have seen that after getting the binary version you just need to use ToString to convert into string "text" format.

<cfset yourText = toString(toBinary(YourData64))>
TiGGiAuthor
Inspiring
March 21, 2008
ToString on it's own doesn't work, I can make it work with tostringToBinary(text)) but Adobe documentation recommends to use BinaryDecode instad of the ToBinary
Participating Frequently
March 21, 2008
Participating Frequently
March 21, 2008
"ToString" function?