Question

I am looking at a MIME segment of an email, which claims to be encoded as base64. The entire value is

ICA=

The conversion Convert.FromBase64String( "ICA=" ) returns a two-byte array, and both values are 32, which looks to me like two spaces. There is no error.

I have read about base64, but I haven't caught why ICA= becomes spaces.

Was it helpful?

Solution

Use the Base64 alphabet to convert "ICA=" to six-digit binary numbers. "I" is 8, which is "001000" in binary. "C" is 2, which is "000010". "A" is 0, which is "000000". Ignore the placeholder "=". Concatenate the binary numbers, and take bytes (8 bits) out of the result at a time, ignoring leftover zeroes. So, you have "001000000010000000", which becomes "00100000" and "00100000", which are both 32, the decimal representation of a space character.

Base64 encoding alphabet and explanation can be found here: https://www.rfc-editor.org/rfc/rfc4648

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top