there's a `toBase64`, is there a `fromBase64` ?
# lucee
d
there's a
toBase64
, is there a
fromBase64
?
best I can do is
Copy code
b64 = toBase64("foo");
bytes = binarydecode(b64, "base64")
s = createObject("java", "java.lang.String").init(bytes, createObject("java", "java.nio.charset.Charset").forName("UTF-8"));
writedump(s); // "foo"
maybe it would be weird to auto assume utf8, idk
b
@David Rogers Reverse base64 with
toBinary()
🙂
Here's a repro in CommandBox
Copy code
❯ #tobase64 test | #tobinary
test
d
i must be holding it wrong, I get a
byte[]
of ascii bytes? https://trycf.com/gist/7127ca8ff502f3d75482fa16bd5cc33f/lucee5?theme=monokai
b
Then pass it through toString()
I almost forgot, CommandBox does an implicit toString when it outputs to the console
Copy code
❯ #tobase64 test | #tobinary | #tostring
test
🙂
d
hah, I had used the member function
foo.toString
and was getting some stringified object ref
b
An array of bytes is a native Java array so I wouldn't expect it to have an member functions
Unless the CF engine itself was doing something with it
And if the byte array is anything other than UTF-8 you'd need to pass the encoding you want used to
toString()
d
toString(...)
it is, thanks
👍 1
b
Yep, and keep in mind, if the thing you base 64's was not a string originally, but say, a PDF file, then you'd obviously not want to use toString!