Base64 Encoding Decoding in Python Programming


Python Programming Base64 Encoding Decoding Code Example
Python Base64 Decode/Encode

In order to do base64 encoding and decoding in Python Programming, make use of the base64 package,

Code Example:
"""
Base 64 Encoding Decoding in
Python Programming

Author: Code2care.org
Date: 03-Apr-2022
Version: 1.0

"""

import base64

plan_text_string = 'Hello there! Python'

# Base64 Encode Example
base64_encoded_string_result = base64.b64encode(plan_text_string.encode('utf-8'))
print(base64_encoded_string_result)

# Base64 Decode Code
base64_encoded_string = 'SGVsbG8gdGhlcmUhIFB5dGhvbg=='
base64_decoded_string_result = base64.b64decode(base64_encoded_string).decode('utf-8')
print(base64_decoded_string_result)
Output:
b'SGVsbG8gdGhlcmUhIFB5dGhvbg=='
Hello there! Python
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.