Hiding a password in a python script (insecure obfuscation only)
Base64 encoding is in the standard library and will do to stop shoulder surfers:
>>> import base64
>>> print(base64.b64encode("password".encode("utf-8")))
cGFzc3dvcmQ=
>>> print(base64.b64decode("cGFzc3dvcmQ=").decode("utf-8"))
password
Here is a simple method:
- Create a python module - let's call it peekaboo.py.
- In peekaboo.py, include both the password and any code needing that password
- Create a compiled version - peekaboo.pyc - by importing this module (via python commandline, etc...).
- Now, delete peekaboo.py.
- You can now happily import peekaboo relying only on peekaboo.pyc. Since peekaboo.pyc is byte compiled it is not readable to the casual user.
This should be a bit more secure than base64 decoding - although it is vulnerable to a py_to_pyc decompiler.