# coding=utf-8 import base64 from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 from library.yinkayo.api.base import ApiBase from library.yinkayo.constants import PUBLIC_KEY class Login(ApiBase): @staticmethod def _get_cipher_text(*args): pubK = "-----BEGIN RSA PUBLIC KEY-----\n" + PUBLIC_KEY + "\n-----END RSA PUBLIC KEY-----" encryptor = PKCS1_v1_5.PKCS115_Cipher(RSA.importKey(pubK)) cipherS = ",".join(args) encrypted_data = encryptor.encrypt(cipherS.encode("ISO-8859-1")) cipherT = base64.b64encode(encrypted_data) return cipherT def login(self): customer, operator, password = self._client.load_login_info() cipherT = self._get_cipher_text(customer, operator, password) publicK = PUBLIC_KEY data = { "JKeypublic": publicK, "Loginciphertext": cipherT, } response = self._post("/WebAPI/Login/ClientLogin", **data) cookies = response.cookies.get_dict() return cookies