Python中的模糊字符串

编程入门 行业动态 更新时间:2024-10-17 07:40:12
本文介绍了Python中的模糊字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个必须传递给一个方法的密码字符串。一切正常,但我不太舒服地将密码存储在明文中。有没有办法模糊字符串或真正加密?我知道混淆可以反向设计,但我认为我至少应该尝试掩盖密码。至少它不会对索引程序看到,或者是一个流浪的眼睛,快速看看我的代码。

我知道pyobfuscate,但我不想要整个程序模糊,只有一个字符串,也可能是整个变量定义的整行。

目标平台是GNU Linux Generic(如果这有所作为) / p>

解决方案

如果你只是想防止随便看一下密码,你可能需要考虑将密码编码/解码为/一个href =docs.python/library/base64.html =noreferrer> base64 。这至少不安全,但密码不会随便人为/机器人可读。

import base64 #编码密码 encoded_pw = base64.b64encode(raw_pw) #解码密码 decoded_pw = base64.b64decode(encoded_pw) / pre>

I have a password string that must be passed to a method. Everything works fine but I don't feel comfortable storing the password in clear text. Is there a way to obfuscate the string or to truly encrypt it? I'm aware that obfuscation can be reverse engineered, but I think I should at least try to cover up the password a bit. At the very least it wont be visible to a indexing program, or a stray eye giving a quick look at my code.

I am aware of pyobfuscate but I don't want the whole program obfuscated, just one string and possibly the whole line itself where the variable is defined.

Target platform is GNU Linux Generic (If that makes a difference)

解决方案

If you just want to prevent casually glancing at a password, you may want to consider encoding/decoding the password to/from base64. It's not secure in the least, but the password won't be casually human/robot readable.

import base64 # Encode password encoded_pw = base64.b64encode(raw_pw) # Decode password decoded_pw = base64.b64decode(encoded_pw)

更多推荐

Python中的模糊字符串

本文发布于:2023-10-23 05:31:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519935.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   模糊   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!