python中密码字符串的Base64编码

时间:2020-06-24 18:17:57

标签: python password-protection

我遇到了以下代码来解码密码字符串,例如我的密码字符串是'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='))

0 个答案:

没有答案