Sunday, September 2, 2012

Python simple base64 encode/decode script

I found the need of encoding and decoding base64 values fast from stdin to stdout (without GUI-crap) and started to look around for tools and i could find a bunch of them, but most of them were with advanced options and parameters.
Sometimes simple is enough so i wrote two scripts and included them in my PATH statement.

----------------------------------
# Base64 Encode stdin to stdout
#! /usr/bin/python
# Filename: b64enc.py
import base64
import sys
base64encoded = base64.b64encode(sys.stdin.read())
print base64encoded

----------------------------------
# Base64 Decode stdin to stdout
#! /usr/bin/python
# Filename b64dec.py
import base64
import sys
base64decoded = base64.b64decode(sys.stdin.read())
print base64decoded


Example:


Enjoy!

No comments:

Post a Comment