python rsa加解密
# pip install rsa import rsa import base64 #生成公私钥 public_key, private_key = rsa.newkeys(1024) msg = ‘今晚8点老地方碰头‘ # 加密 encryptd_msg = rsa.encrypt(msg.encode(), public_key) encryptd_msg_str = base64.b64encode(encryptd_msg).decode() # 解密 encryptd_msg = base64.b64decode(encryptd_msg_str.encode()) msg = rsa.decrypt(encryptd_msg, private_key).decode() print(msg) # 今晚8点老地方碰头 # 对象转字符串 public_key_str = public_key.save_pkcs1() private_key_str = private_key.save_pkcs1() # 字符串转对象 public_key = rsa.PublicKey.load_pkcs1(public_key_str.encode())
来源:站长
相关推荐
hulao 2020-06-12
STchaoL 2020-06-04
逍遥友 2020-06-02
singer 2020-05-30
dailinqing 2020-05-26
yuanran0 2020-05-09
happyfreeangel 2020-04-26
BraveWangDev 2020-03-08
rein0 2020-01-29
magicandy 2020-01-02
mmyCSDN 2020-01-06
ConquerALL 2013-06-08
taiyangshenniao 2019-12-26
seekerhit 2019-12-24
会哭的雨 2019-12-19