def send_data_packet(self, route_address, data_dict): encrypt_data = utils.json_encrypt(secret_key, json.dumps(data_dict)) data_packet = packet.Packet.gen_packet('DATA', encrypt_data) if DEBUG: print '[LOG][%s]: create a DATA packet which uuid is %s' % (time.ctime(), data_packet.uuid.encode('hex')) self.__caching_dict[data_packet.uuid.encode('hex')] = data_packet self.__send_post_packet(route_address, data_packet.uuid.encode('hex'))
def send_data_packet(self, route_address, data_dict): encrypt_data = utils.json_encrypt(secret_key, json.dumps(data_dict)) data_packet = packet.Packet.gen_packet('DATA', encrypt_data) if DEBUG: print '[LOG][%s]: create a DATA packet which uuid is %s' % ( time.ctime(), data_packet.uuid.encode('hex')) self.__caching_dict[data_packet.uuid.encode('hex')] = data_packet self.__send_post_packet(route_address, data_packet.uuid.encode('hex'))
def __send_ack_packet(self, route_address, packet_uuid_hex): payload = {'uuid': packet_uuid_hex, 'timestamp': time.time() * 100} encrypt_data = utils.json_encrypt(secret_key, json.dumps(payload)) ack_packet = packet.Packet.gen_packet('ACK', encrypt_data) self.__sending_queue.put((route_address, ack_packet))
def test_encrypt_and_decrypt(self): key_hex = utils.gen_aes_key_hex() content = json.dumps({'command': 'test'}) cipher_string = utils.json_encrypt(key_hex, content) after = utils.json_decrypt(key_hex, cipher_string) self.assertEqual(after, content, 'test encrypt and decrypt fail')