在 python 脚本中隐藏密码(仅限不安全的混淆) [英] Hiding a password in a python script (insecure obfuscation only)

查看:63
本文介绍了在 python 脚本中隐藏密码(仅限不安全的混淆)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建 ODBC 连接的 python 脚本.ODBC 连接是使用连接字符串生成的.在此连接字符串中,我必须包含此连接的用户名和密码.

是否有一种简单的方法可以在文件中隐藏此密码(只是在我编辑文件时没有人可以读取密码)?

解决方案

Base64 编码 在标准库中,可以阻止肩部冲浪:

<预><代码>>>>导入 base64>>>打印(base64.b64encode(密码".编码(utf-8")))cGFzc3dvcmQ=>>>打印(base64.b64decode(cGFzc3dvcmQ =").解码(utf-8"))密码

I have got a python script which is creating an ODBC connection. The ODBC connection is generated with a connection string. In this connection string I have to include the username and password for this connection.

Is there an easy way to obscure this password in the file (just that nobody can read the password when I'm editing the file) ?

解决方案

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

这篇关于在 python 脚本中隐藏密码(仅限不安全的混淆)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆