python md5 && base64加密解密

md5加密(不可逆)

import hashlib

pwd = '123'
obj = hashlib.md5()
obj.update(pwd.encode('utf-8'))
res = obj.hexdigest()
print(res)

image

避免撞库风险,加盐

# -*- coding: utf-8 -*-
import hashlib

pwd = '123'
## 加盐
obj = hashlib.md5("asdsahjghjg".encode('utf-8'))
obj.update(pwd.encode('utf-8'))
res = obj.hexdigest()
print(res)

image

base64加密解密

## 加密
import base64
import getpass
## 在linux系统中,输入密码屏幕不显示所输入的密码:getpass
pwd = getpass.getpass("请输入您要加密的密码: \n")
print("加密后内容:\n\n",'\033[0;36m{}\033[0m'.format(base64.b64encode(pwd.encode("utf8"))))
print("\n可直接将加密后的内容全部放到对应的变量中")

image

## 解密
import base64
res=base64.b64decode(b'MTIzNDU2')
print(res)

image

posted @ 2021-12-10 14:01  咖啡馆  阅读(294)  评论(0)    收藏  举报