This is probably a simple answer but I can't seem to figure it out. I am trying to decode Base32 sections of a message but not getting the results I am expecting from the Apache Commons decoder.
base32 = new Base32(true);
byte[] value = base32.decode(new String("F=======").getBytes());
value is an empty array
I think I had completely misunderstood your question at first.
Why does the Apache Commons Base32 decoding return any empty array here?
Answer. It's not just Apache Commons Base32 decoding library, but any well-written base32 decoding algorithm will return an empty value. Why? It's just not possible for the base32 encoding algorithm to have generated a string "F=======" as a result of encoding.
Let's understand the base32 decoding algorithm with an example of a decoded string "F8======". Note that "=" is not a real base32 character. It is just used for padding. So the actual encoded string here is "F8".
If you look at the Base32hex character map, the decimal values of F and 8 are 15 and 8 respectively which are expressed in binary as 00001111 and 00001000 respectively. As the term Base32 implies, it works in a set of 5 bits (32 = 2^5). So the same binary numbers when grouped in a set of 5 bits are expressed as 01111 and 01000 respectively. As per the algorithm, these 5-bit sets are placed together as "01111 01000" or "0111101000" without spaces. Then, this number is grouped into sets of 8 bits each from left which gives "01111010 00". Here the second set is an incomplete set since it doesn't have all 8 bits so it is discarded leaving us with a value of 01111010 which when converted to decimal gives 122. The value 122 maps to the ascii character 'z'. So the answer of decoding "F8" is "z".
Now if you apply this algorithm in your example of "F=======" which is just "F" if you discard the padding, you will get only set of "01111" which is an incomplete set because it doesn't have all the 8 bits. So an empty value is returned as a result.