0% found this document useful (0 votes)
49 views

Base64 Encoding: Craig Jacquez

Base64 encoding converts binary data like images or executables into text so it can be sent via email or stored in text-based formats. It represents the binary data in 6-bit groups and maps each group to a character in a 64-character index table to produce an ASCII string. Decoding reverses the process to recover the original binary data from the encoded text. Base64 is commonly used to embed images in HTML and transmit files over protocols that only support text, but it is not encryption and does not use a key.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Base64 Encoding: Craig Jacquez

Base64 encoding converts binary data like images or executables into text so it can be sent via email or stored in text-based formats. It represents the binary data in 6-bit groups and maps each group to a character in a 64-character index table to produce an ASCII string. Decoding reverses the process to recover the original binary data from the encoded text. Base64 is commonly used to embed images in HTML and transmit files over protocols that only support text, but it is not encryption and does not use a key.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Base64 encoding

Craig Jacquez

[email protected]
Encoding - Decoding
What is Base64?
• 2^6 = 64

• 64 bits can represent ASCII text

• Standard base64 index table on next page


ASCII text – index table
What base64 encoding is not…
ENCRYPTION = NOT!
ENCRYPTION = NOT!
ENCRYPTION = NOT!
ENCRYPTION = NOT!
ENCRYPTION = NOT!
ENCRYPTION = NOT!
Encoding does not use a key, encryption does
Why base64?
• http – text
• Email – text
• Base64 uses 64 characters to encode strings. ‘A-Z’, ‘a-z’,
‘0-9’, ‘+’, and ‘/’ are the 63 real characters (without the
‘’, of course), and the ‘=’ sign is the padding.
• Binary-to-text encoding

• How to send non ASCII text data then???


• Binary data, images, executables, etc.
Base64 Encoding
1)Start with data to encode (can be binary)
– Example data =“food”
2) Convert data to 8-bit binary
f o o d
01100110 01101111 01101111 01100100
Base64 Encoding
3) Convert to 6-bit binary

f o o d
01100110 01101111 01101111 01100100 // 8 bit binary
01100110011011110110111101100100 // Bit Stream
011001 100110 111101 101111 011001 00 // 6 bit binary
Calculate 6bit binary value
f o o d
01100110 01101111 01101111 01100100 // 8 bit binary
01100110011011110110111101100100 // bit stream
011001 100110 111101 101111 011001 00 // 6 bit binary
25 38 61 47 25 0
Convert 6 bit to ASCII text
f o o d
01100110 01101111 01101111 01100100
01100110011011110110111101100100
11001 100110 111101 101111 011001 000000
25 38 61 47 25 0 // index
Z m 9 v Z A // base64 encoded

Zm9vZA = ASCII text string for the value “food”


Additional Base64 Info
• Note we went from 4 characters to 6
• All base64 encoded strings must be built on 4
character string blocks
• Since our result is not a multiple of 4 chars
• Padding is required to bring up to 4
• Correctly encoded base64 result is Zm9vZA==
Base64 decoding
• Reverse the previous encoding steps!

• Remember to strip any pad characters “=“


Base64 – miscellaneous
Email servers - some limited to 72 chars per line

<img alt="Embedded Image"


src="data:image/png;base64,iVBORw0KGgoAA
AkjNSUhEUgAZADIA" />

You might also like