一日一技:如何在Python中加密密码

    作者:Python编程之美更新于: 2020-05-19 15:20:21

    如何在Python中加密密码,加密密码会将密码编码为随机字符序列。使用base64.b64encode()加密密码。

    一日一技:如何在Python中加密密码_Python视频_Python视频课程_Python课程_课课家

    调用str.encode(“ utf-8”)将密码str编码为UTF-8字符串。 调用base64.b64encode(utf_string)将上一步中的utf_string编码为基本64字符串。 调用base64.b64decode(b64_string)将b64_string解码回str。

    1. password = "my_password".encode("utf-8"
    2.  
    3. encoded = base64.b64encode(password
    4. print(encoded) 
    5.  
    6. decoded = base64.b64decode(encoded) 
    7. print(decoded) 

    输出:

    1. b'bXlfcGFzc3dvcmQ='  
    2. b'my_password' 

课课家教育

未登录

1