Base64 encoding uses only 6 bits (corresponding to 2^6 = 64 characters), hence the name Base64. The 64 characters are 10 digits, 26 lowercase characters, 26 uppercase characters, the addition sign (+) and /
Base64 encoding is a two-step process. A stream of bytes is divided into groups, each consisting of three consecutive bytes. Each group (three sequential bytes, each consisting of eight bits) is converted to four numbers of six bits. In the second step, numbers are converted to ASCII characters using the Base64 encoding table.
For example,
Step 1: The string "$t@" (36, 116, 64), the corresponding bit stream is 001001000111010001000000, which in turn corresponds to the 6-bit values 9, 7, 17 and 0.
36 = 00100100
116 = 01110100
64 = 01000000
001001 = 9
000111 = 7
010001 = 17
000000 = 0
Step 2: These numbers are converted to ASCII characters using the Base64 encoding table. The 6-bit values of our example translate to the ASCII sequence "JHRA".
9 => J
7 => H
17 => R
0 => A
Note: If the size of the original data in bytes is not multiple of three, there may be one or two 8-bit bytes remaining. The solution is to append enough bytes with a value of '0' to create a 3-byte group.
These artificial trailing '0's are not encoded using the encoding table. They are represented by a 65th character. The Base64 padding character is '='.
|
Copyright © 2014 CA Technologies.
All rights reserved.
|
|