class MyRsa():
def __init__(self, pri_key_file, pub_key_file):
with open(pri_key_file, mode='rb') as privatefile:
private_keydata = privatefile.read()
self.privkey = rsa.PrivateKey.load_pkcs1(private_keydata)
with open(pub_key_file, mode='rb') as publicfile:
public_keydata = publicfile.read()
self.pubkey = rsa.PublicKey.load_pkcs1(public_keydata)
def encrypt_b64(self, msg):
crypto_text = rsa.sign(msg.encode('utf8'), self.privkey, 'SHA-1')
res = base64.b64encode(crypto_text)
res = res.decode()
logz.info(msg)
#
logz.info(self.privkey)
logz.info(res)
return res
rsa1 = MyRsa(pri_key_file=pri_key_file, pub_key_file=pub_key_file)
signature = rsa1.encrypt_b64(sign_str)
print(signature)
试试,拷贝了一段。