Base 64 encoding/decoding
b2a_base64
converts a bytes object to a
Base64 representation.
a2b_base64
does the opposite.
>>> import binascii
>>> print(binascii.b2a_base64(b'hello world', newline=False).decode('ascii'))
aGVsbG8gd29ybGQ=
>>> print(binascii.a2b_base64(b'aGVsbG8gd29ybGQ=').decode('ascii'))
hello world
Convert bytes to hexadecimal representation and vice versa
>>> binascii.hexlify(b'Rene\x17')
b'52656e6517'
>>> binascii.unhexlify(b'52656e6517')
b'Rene\x17'
Note that
hexlify()
returns a
bytes
object.
A string object can be obtained by directly calling .hex()
on the bytes object:
>>> b'ABC'.hex()
'414243'