python中密码字符串的Base64编码

2024-04-19 11:37:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

下面的代码隐藏了我的确切密码,即“samplepassword”,但任何使用encodedvalue的人都可以使用相同的密码轻松找到原始密码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='))

Tags: 字符串代码httpsio密码编码valueutils