Base64
- is an encoding between (a subset of ASCII characters) ↔ (sequences of 6 bits). In other words, each Base64 digit represents exactly 6 bits of data)
Base64 Table
|
Decimal |
Binary |
Base46 |
Decimal |
Binary |
Base64 |
Decimal |
Binary |
Base64 |
Decimal |
Binary |
Base64 | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
0 |
000000 |
|
16 |
010000 |
|
32 |
100000 |
|
48 |
110000 |
| |||
|
1 |
000001 |
|
17 |
010001 |
|
33 |
100001 |
|
49 |
110001 |
| |||
|
2 |
000010 |
|
18 |
010010 |
|
34 |
100010 |
|
50 |
110010 |
| |||
|
3 |
000011 |
|
19 |
010011 |
|
35 |
100011 |
|
51 |
110011 |
| |||
|
4 |
000100 |
|
20 |
010100 |
|
36 |
100100 |
|
52 |
110100 |
| |||
|
5 |
000101 |
|
21 |
010101 |
|
37 |
100101 |
|
53 |
110101 |
| |||
|
6 |
000110 |
|
22 |
010110 |
|
38 |
100110 |
|
54 |
110110 |
| |||
|
7 |
000111 |
|
23 |
010111 |
|
39 |
100111 |
|
55 |
110111 |
| |||
|
8 |
001000 |
|
24 |
011000 |
|
40 |
101000 |
|
56 |
111000 |
| |||
|
9 |
001001 |
|
25 |
011001 |
|
41 |
101001 |
|
57 |
111001 |
| |||
|
10 |
001010 |
|
26 |
011010 |
|
42 |
101010 |
|
58 |
111010 |
| |||
|
11 |
001011 |
|
27 |
011011 |
|
43 |
101011 |
|
59 |
111011 |
| |||
|
12 |
001100 |
|
28 |
011100 |
|
44 |
101100 |
|
60 |
111100 |
| |||
|
13 |
001101 |
|
29 |
011101 |
|
45 |
101101 |
|
61 |
111101 |
| |||
|
14 |
001110 |
|
30 |
011110 |
|
46 |
101110 |
|
62 |
111110 |
| |||
|
15 |
001111 |
|
31 |
011111 |
|
47 |
101111 |
|
63 |
111111 |
|
|
padding |
= | |
Output Padding
The final == sequence indicates that the last group contained only one byte, and = indicates that it contained two bytes. The example below illustrates how truncating the input of the above quote changes the output padding:
|
INPUT |
OUTPUT | |||||
|---|---|---|---|---|---|---|
|
Text |
# of Chars |
# of Bits |
Base64 Text |
# of Chars |
# of Bits |
Padding |
|
pleasure |
8 |
64 |
cGxlYXN1cmU= |
12 |
72 |
1 |
|
pleasur |
7 |
56 |
cGxlYXN1cg== |
12 |
72 |
2 |
|
pleasu |
6 |
48 |
cGxlYXN1 |
8 |
48 |
0 |
|
pleas |
5 |
40 |
cGxlYXM= |
8 |
48 |
1 |
|
plea |
4 |
32 |
cGxlYQ== |
8 |
48 |
2 |
Encoding/Decoding Base64
encode
echo -n ‘input’ | openssl base64
echo -n ‘hello’ | base64
openssl base64 -in plain.txt -out base64.txt
decode
echo -n ‘aGVsbG8=’ | base64 —decode
base64 —decode base64.txt > plain.txt