I am currently trying to decode some base64 CDATA from Youtube Comments. It seems to decode it into a binary fine, but not sure how to convert it to a string.
<?xml version="1.0" encoding="utf-8"?><root><comments><![CDATA[EAEYACCQTg==]]></comments></root>
And in elixir
iex> Base.url_decode64!("EAEYACCQTg==")
<<16, 1, 24, 0, 32, 144, 78>>
And if I try to toss it into a utf8 string, it doesn't match.
iex> <<x::utf8>> = Base.url_decode64!("EAEYACCQTg==")
** (MatchError) no match of right hand side value: <<16, 1, 24, 0, 32, 144, 78>>
<<65, 66, 67>>is exactly the same as"ABC", it's just a matter of Elixir pretty printing it for you. When a binary only contains valid codepoints it will be printed as string, otherwise it will be printed as a "raw" binary. The point is: the bytes you have decoded are not a valid string, for example strings cannot contain0bytes. Probably there's another level of encoding involved here. Do you happen to know what the result should exactly look like? - Patrick Oscity