DEV Community

Converting a string to Base64 manually

Vivek Kumar on January 07, 2024

As a web developer, you must have heard or even used Base64 encodings. Generally we convert some texts or urls to Base64 encoded string. To do this...
Collapse
 
hseritt profile image
Harlin Seritt

Wonderful, thanks for the write up, Vivek! I've had to do this recently at work.

Collapse
 
iamspathan profile image
Sohail Pathan

Nice explanation, Vivek. Now I know what goes on behind in the encoding and decoding part.
Since you mentioned:

"To do this, we either use programming languages' methods or we use some third-party tools."

One of the third-party tools is ApyHub as well, which supports base64 inputs for certain APIs like file conversions.

Sharing as a resource. :)

Collapse
 
vvkkumar06 profile image
Vivek Kumar

Thanks for sharing

Collapse
 
ooosys profile image
oOosys • Edited

Hmmm ... what is the point of adding one more to the myriads of explanations already available on Internet? Covering "hi" instead of "Man" and "Ma" and "M" which is a more complete set of examples???

Collapse
 
ibnsamy96 profile image
Mahmoud Ibn Samy

I liked how you simplified the whole process splitting it into small steps, but why would we convert text into base64? are there any applicable uses of that?

Collapse
 
godinhojoao profile image
João Godinho

Nice!! I also have a post explaining how base64 works and its use cases: dev.to/godinhojoao/base64-encoding...

Collapse
 
wyattdave profile image
david wyatt

Nice

Collapse
 
tainv2002 profile image
Nguyễn Văn Tài

Good

Collapse
 
nxquan profile image
nxquan

Good

Collapse
 
dagnelies profile image
Arnaud Dagnelies • Edited

That's not base64, it's base64url. Confusing both leads to trouble for everyone. The (deprecated) function btoa encodes to base64 with + and / instead of base64url with - and _.

Collapse
 
fjones profile image
FJones

btoa isn't deprecated anymore afaik, it just comes with documentation warning against use with Unicode.

Collapse
 
dagnelies profile image
Arnaud Dagnelies

Yes, you are right. btoa is not deprecated, actually it will probably stay forever. It's just my IDE that mislead me recently by annotating it that way.