Base64 in Python: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 2: Line 2:
* [[Python_Code_Examples#Code_Examples|Python Code Examples]]
* [[Python_Code_Examples#Code_Examples|Python Code Examples]]
=Overview=
=Overview=
=Encode=
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
import base64
import base64
binary_data = ...
binary_data = ...
c = base64.b64encode(binary_data).decode('utf-8')
c = base64.b64encode(binary_data).decode('utf-8')
</syntaxhighlight>
=Decode=
<syntaxhighlight lang='py'>
import base64
base64_text = ...
binary_data = base64.b64decode(base64_text)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 05:29, 10 June 2022

Internal

Overview

Encode

import base64
binary_data = ...
c = base64.b64encode(binary_data).decode('utf-8')

Decode

import base64
base64_text = ...
binary_data = base64.b64decode(base64_text)