一日一技:如何在Python中加密密码
域名 2025-10-07 09:56:46
0
如何在Python中加密密码
加密密码会将密码编码为随机字符序列。日技
使用base64.b64encode()加密密码
调用str.encode(“ utf-8”)将密码str编码为UTF-8字符串。加密 调用base64.b64encode(utf_string)将上一步中的香港云服务器密码utf_string编码为基本64字符串。 调用base64.b64decode(b64_string)将b64_string解码回str。服务器托管日技
加密password = "my_password".encode("utf-8") encoded = base64.b64encode(password) print(encoded) decoded = base64.b64decode(encoded) print(decoded)输出:
加密bbXlfcGFzc3dvcmQ= bmy_password