Encoding with Base64

Base64 is an encoding method that is used frequently to this day. It is very easily encoded and decoded, which makes it both extremely useful and also dangerous. Base64 is not used as commonly anymore to encode sensitive data, but there was a time where it was.

Getting ready

Thankfully for the Base64 encoding, we do not require any external modules.

How to do it…

To generate the Base64 encoded string, we can use default Python features to help us achieve it:

#!/usr/bin/python
msg = raw_input('Please enter the string to encode: ')
print "Your B64 encoded string is: " + msg.encode('base64')

How it works…

Encoding a string in Base64 within Python is very simple and can be done in a two-line script. To begin we need to have the string ...

Get Python: Penetration Testing for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.