def _authenticate(self): error = 'Authentication error' login = b64.encode(self.sender.encode()) + b'\r\n' self.send_command(b'AUTH LOGIN\r\n', error, '334', True) self.send_command(login, error, '334', True) password = b64.encode(getpass().encode()) + b'\r\n' self.send_command(password, error, '235')
def auth(self): print("auth login") self.socket.send(b"auth login\r\n") _ = self.get_ans() login = bytes(b64.encode(self.credentials.login) + '\r\n', encoding="utf8") print(login) self.socket.send(login) _ = self.get_ans() password = bytes(b64.encode(self.credentials.password) + '\r\n', encoding="utf8") print(password) self.socket.send(password) ans = self.get_ans() if ans[:3] != "235": self.crush("Auth wasn't successful")
def serialize(self) -> Dict[str, Union[str, int, bool, None, Dict, List]]: return { "algorithm": "scrypt", "log2_n": self.log2_n, "r": self.r, "p": self.p, "salt": b64.encode(self.salt) }
def serialize(self) -> Dict[str, Union[str, int, bool, None, Dict, List]]: return { "algorithm": self.type_to_str(self.type), "version": self.version, "time_cost": self.time_cost, "memory_cost": self.memory_cost, "parallelism": self.parallelism, "salt": b64.encode(self.salt), }
def main( hexstr='49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d' ): # Convert to bytes bytes = utils.hexstr_bytes(hexstr) # Calculate base64 bytes enc_bytes = b64.encode(bytes) # Convert bytes to string str = utils.bytes_string(enc_bytes) print(str)
def send_raw(self, data, target): packet = str(target) + DEVICEID + b64.encode(data) sum = b64.checksum(packet) packet += sum + '\r\n' self._packetcond.acquire() self._packetlist.append(packet) self._packetcond.release() self._lock.acquire() debug('Sent packet %r', packet) self._serial.write(packet) self._serial.flush() self._lock.release() Timer(get_standoff(), lambda: self._check_recieved(packet)).start()
def login(offset=0): properties = getConfig() url = properties['ENDPOINT']['endpoint_auth'] myobj = { 'email': encode(properties['USER']['username']), 'password': encode(properties['USER']['password']) } args = {"Content-Type": "application/json;"} if offset else {} try: response = requests.post(url, json=myobj, params=args) except Exception as e: print("Ocurrió un error al realizar la Autenticación: ", e) if response.status_code == 200: payload = response.json() print("=> Autenticación correcta") print(payload) return payload.get('token') else: print("=> Autenticación incorrecta") return None
def format_image(self, image): b_boundary = b'--' + self.boundary.encode() + b'\r\n' b_img_ext = image[-3:].encode() image_name = image[image.rfind('\\') + 1:].encode() f_image = b_boundary + \ b'Content-Disposition: attachment;\r\n' + \ b'\tfilename="' + image_name + b'"\r\n' + \ b'Content-Transfer-Encoding: base64\r\n' + \ b'Content-Type: image/' + b_img_ext + b';\r\n' + \ b'\tname="' + image_name + b'"\r\n\r\n' img_data = get_binary_image(image) img_base64_data = b64.encode(img_data) n = len(img_base64_data) // 76 for i in range(n + 1): f_image += img_base64_data[i * 76:(i + 1) * 76] + b'\r\n' return f_image
def to_utf8(s): return "=?utf-8?b?{}?=".format(b64.encode(s.encode(encoding='utf-8')))
def encode_image(self): f = open(self.path, "rb").read() return b64.encode(f)
def serialize(self) -> Dict[str, Union[str, int, bool, None, Dict, List]]: return {"algorithm": "aes-256-gcm", "nonce": b64.encode(self.nonce)}
def serialize(self) -> Dict[str, Union[str, int, bool, None, Dict, List]]: return { "algorithm": "chacha20-poly1305", "nonce": b64.encode(self.nonce) }