DEV Community

Discussion on: Base64 Explained

Collapse
 
lexlohr profile image
Alex Lohr

When you encrypt a string using base64...

Base64 is not an encryption. For an encryption, you would need a key to decrypt the data. It is an encoding.

The main reason for base64 is that some protocols dedicated 2 bits of each byte for error correction data, so in order to transmit anything, it would have to be encoded in base64 (the same reason applies for 1 bit and Uuenc).

If our data would read "Ok.", that would be '01001111 01101011 00101110' in base2, better known as binary. To get base 64, we split the data not in segments of 8, but of 6 bits: '010011 110110 101100 101110' convert them back to numbers from 0-63, which would make '19 54 44 46' and then use these as indices in a list of A-Za-z0-9+ and use the equal sign for padding, which gives us 'T2su'.

Collapse
 
hamiecod profile image
Hargunbeer Singh

Thanks Alex for correcting me and sharing the useful information. I'll edit the blog and give credits to you for sharing the information.

Collapse
 
ibrahimcesar profile image
Ibrahim Cesar

Good call! Is a little detail that sometimes led people, specially beginners to think they are “encrypting” data.