import rsa
先生成一对密钥,然后保存.pem格式文件,当然也可以直接使用
(pubkey, privkey) = rsa.newkeys(512)
pub = pubkey.save_pkcs1()
pri = privkey.save_pkcs1()
load公钥和密钥
message = '123.234'.encode('utf-8')
pubkey = rsa.PublicKey.load_pkcs1(pub)
privkey = rsa.PrivateKey.load_pkcs1(pri)
用公钥加密、再用私钥解密
crypto = rsa.encrypt(message, pubkey)
print(crypto)
crypto = int.from_bytes(crypto, byteorder='little', signed=True)
print(crypto)
crypto = crypto.to_bytes(crypto, byteorder='little', signed=True)
message = rsa.decrypt(crypto, privkey)
print(message.decode('utf-8'))
在倒数第三行代码那儿将整型转为字节型显示溢出报错,具体修改方案不知道怎么修改,希望可以帮助一下