Framework EDI Reference. Encoding Mechanism
Base64

The Base64 encoding converts 8-bit characters into a universal character set, which are represented identically in ASCII and EBCDIC.  The characters are indexed into a 64 printable character set table, and must be in the following order:

Index Value Encode Char
00 A
01 B
02 C
03 D
04 E
05 F
06 G
07 H
08 I
09 J
10 K
11 L
12 M
13 N
14 O
15 P
16 Q
Index Value Encode Char
17 R
18 S
19 T
20 U
21 V
22 W
23 X
24 Y
25 Z
26 a
27 b
28 c
29 d
30 e
31 f
32 g
33 h
Index Value Encode Char
34 i
35 j
36 k
37 l
38 m
39 n
40 o
41 p
42 q
43 r
44 s
45 t
46 u
47 v
48 w
49 x
50 y
Index Value Encode Char
51 z
52 0
53 1
54 2
55 3
56 4
57 5
58 6
59 7
60 8
61 9
62 +
63 /
(PAD) =

 

The procedure for encoding is as follows:

  1. The data is subdivided into 3-byte groups forming a 24-bit stream.

    Example .  The 3-byte word "The" has the following 24-bit stream (yellow).

    Text T h e
    Byte Hex 0x54 0x68 0x65
    Bit Stream 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1

  2. The 24-bit stream is further subdivided into 6 bits.

    Example .  The 24-bit stream for the word "The" is subdivided as follows:

    Text T h e
    Byte Hex 0x54 0x68 0x65
    Bit Stream 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1
    6-Bit Group 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1
    6-Bit Value 21 6 33 37

  3. The decimal value of each of the 6-bit stream is then mapped to Base64 table for their corresponding encoded character.

    Example .  The 6-bit values are then mapped as follows to the Base64 table:

    Text T h e
    Byte Hex 0x54 0x68 0x65
    Bit Stream 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1
    6-Bit Group 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1
    6-Bit Value 21 6 33 37
    Encoding V G h l

    The resulting encoding for the word "The" is "VGhl".
  4. Because the data is subdivided in groups of 3 bytes, there are some cases where the end of data has only 2 bytes or 1 byte left.  These are handled as follows:


The following shows the encoding transformation of the string "The car".  The encoded result is "VGhlIGNhcg==".  The actual encoded byte stream is shown in the last row.

Text T h e SP c a r NULL NULL
Byte Hex 0x54 0x68 0x65 0x20 0x63 0x61 0x72 0x00 0x00
Bit Stream 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6-Bit Group 0 1 0 1 0 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6-Bit Value 21 6 33 37 8 6 13 33 28 32 0 0
Encoding V G h l I G N h c g = =
Byte Stream 0x56 0x47 0x68 0x65 0x49 0x47 0x6E 0x68 0x63 0x67 0x3D 0x3D