import rsa import requests (pubkey, privkey) = rsa.newkeys(1024) with open("public.pem", "w+") as f: f.write(pubkey.save_pkcs1().decode()) with open("private.pem", "w+") as f: f.write(privkey.save_pkcs1().decode()) with open("public.pem", "r") as f: pubkey = rsa.PublicKey.load_pkcs1(f.read().encode()) with open("private.pem", "r") as f: privkey = rsa.PrivateKey.load_pkcs1(f.read().encode()) message = "hello world" print("======加密前=====>", message) crypto = rsa.encrypt(message.encode(), pubkey) print("======加密后=====>", crypto) msg = rsa.decrypt(crypto, privkey).decode() print("======解密后=====>", msg)