Encode String using Base64 in Python

Base64 encoding schemes are commonly used when there is a need to encode binary data, especially when that data needs to be stored and transferred over media that are designed to deal with text. This encoding helps to ensure that the data remains intact without modification during transport.

Code to Encode

import base64

message = "JD Bots"
message_bytes = message.encode('utf-8')
base64_bytes = base64.b64encode(message_bytes)
base64_message = base64_bytes.decode('utf-8')

print(message + " -> " + base64_message)

Output

Thank you All!!! Hope you find this useful.


One thought on “Encode String using Base64 in Python

Add yours

Leave a Reply

Up ↑

Discover more from JD Bots

Subscribe now to keep reading and get access to the full archive.

Continue reading