首页 > 解决方案 > python中密码字符串的Base64编码

问题描述

我遇到了以下代码来解码密码字符串,例如我的密码字符串是“samplepassword”,我可以使用 base64 算法对其进行编码,并得到以下编码值。我只是使用 https://io/Utils/Base64/ 来查找编码值。"c2FtcGxlcGFzc3dvcmQ="

下面的代码隐藏了我的确切密码“samplepassword”,但任何使用编码值的人都可以使用相同的 https://io/Utils/Base64/ 轻松找到原始密码。

我对理解 base64 模块提供的安全性感到困惑,请建议一些最佳实践来隐藏 python 代码中的密码。

def decode(encoded_value):
    try:
        import base64
        try:
            decoded_value = base64.b64decode(encoded_value).decode('ascii')
            return decoded_value
        except TypeError as e:
            raise TypeError("Attempted to decode {value} once. Illegal Value. ".format(value=encoded_value))
    except ImportError:
        raise ImportError("Base64 import failed")
print(decode('c2FtcGxlcGFzc3dvcmQ='))

标签: pythonpassword-protection

解决方案


推荐阅读