b64encode() / b64decode - unbalanced encoding
16:41 29 Jul 2026

Any idea why the output from b64encode() needs to be decoded with utf-8 to convert it to a string while the output from b64decode needs to be decoded with utf-32 to do the same?

InStr = r"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

IntermediateStr =   base64.b64encode(
                        InStr.encode("utf-32")
                    ).decode("utf-8")

OutStr =            base64.b64decode(
                        IntermediateStr.encode("utf-32")
                    ).decode("utf-32")

print(f"{InStr= }")
print(f"{type(IntermediateStr)= }", f"{IntermediateStr= }")
print(f"{OutStr=}")

exit()
python python-3.x