def test_rsa_encrypt_decrypt(self): from wechatpy.pay.utils import rsa_encrypt, rsa_decrypt target_string = 'hello world' with open(os.path.join(_CERTS_PATH, 'rsa_public_key.pem'), 'rb') as public_fp, \ open(os.path.join(_CERTS_PATH, 'rsa_private_key.pem'), 'rb') as private_fp: encrypted_string = rsa_encrypt(target_string, public_fp.read(), b64_encode=False) self.assertEqual(rsa_decrypt(encrypted_string, private_fp.read()), target_string.encode('utf-8'))
def _rsa_encrypt(self, data): if not getattr(self, "_rsa_public_key", None): self._rsa_public_key = self.get_rsa_public_key()["pub_key"] return rsa_encrypt(data, self._rsa_public_key)
def _rsa_encrypt(self, data): if not getattr(self, '_rsa_public_key', None): self._rsa_public_key = self.get_rsa_public_key()['pub_key'] return rsa_encrypt(data, self._rsa_public_key)