Re: base64 Incorrect Padding



Max Erickson wrote:
MRAB <python@xxxxxxxxxxxxxxxxxxx> wrote:

Brandon Fredericks wrote:
I did a search within this group, but couldn't find any
information on this.

I am sending base64 encoded data as the content over http using
urllib2 urlopen. When I receive the data and attempt to decode
it, I get an "Incorrect Padding" error. Is there a simple way to
fix this? A better way to send and receive the data possibly
(using base64 of course)?
Base-64 encodes 3 bytes (echo in the range 0-255) to 4 bytes
(each in a more restricted range). The length of the output is
_always_ a multiple of 4 (ignoring whitespace); the method adds
extra padding bytes (ASCII '=') to ensure that this is the case
if the length of the input isn't a multiple of 3.

So, if decoding raises an "Incorrect Padding" error then strip
out any whitespace and append extra ASCII '=' to make its length
a multiple of 3, then try decoding again. (Or you could just
repeatedly add one pad character and retry, up to 3 times.)

The length of the encoded string should be a multiple of 4 (as you state in the second sentence of your post), not a multiple of 3.

Oops, correct! :-)
.



Relevant Pages

  • Re: base64 Incorrect Padding
    ... The length of the output is _always_ a multiple ... if decoding raises an "Incorrect Padding" error then strip out any ...
    (comp.lang.python)
  • Re: base64 Incorrect Padding
    ... if the length of the input isn't a multiple of 3. ... if decoding raises an "Incorrect Padding" error then strip ... out any whitespace and append extra ASCII '=' to make its length ...
    (comp.lang.python)
  • Re: Address decoding within SOC
    ... This is why I am asking where the address decoding logic ... For multiple master system, there are multiple ... Please notice that peripherals like UART will be more likely to be ... You can connect an AXI to APB bridge to a PL300 ...
    (comp.arch.embedded)
  • Re: Address decoding within SOC
    ... This is why I am asking where the address decoding logic ... For multiple master system, there are multiple ... Please notice that peripherals like UART will be more likely to be ... You can connect an AXI to APB bridge to a PL300 ...
    (comp.arch.embedded)