def decrypt_cookies(cookies): encryption = Encryption() decrypted = {} for key, value in cookies.iteritems(): Logger.d("Decrypting " + str((key, value))) try: decrypted[key] = encryption.decrypt(value) except EncryptionError: pass return decrypted
class Decoder: MODES = {'GCM': 8} MODE_LENGTH = 1 def __init__(self, password, image_folder_path): self.image_folder_path = image_folder_path self.mode = None self._gcm = None self._password = password self._data_length = 0 self.extractor = Extractor(image_folder_path) def get_header_length(self): return GCM.get_iv_length() + GCM.get_salt_length() def decode_header(self, raw_header): # assume raw_header is bytearray of values salt_end = GCM.get_salt_length() gcm_end = salt_end + GCM.get_iv_length() password_salt = bytes(raw_header[:salt_end]) iv = bytes(raw_header[salt_end:gcm_end]) self._gcm = GCM(iv=iv, password_salt=password_salt) self._gcm.make_key(self._password) del self._password def get_tag(self, raw_data): tag = bytes(raw_data[-GCM.get_tag_length():]) self._gcm.set_tag(tag) def decrypt_and_save_data(self, raw_data, destination_file): decrypted = self._gcm.decrypt( raw_data[self.get_header_length():-GCM.get_tag_length()]) # with open("temp", "wb") as f: # f.write(decrypted) self._gcm.decrypt_finalize() with open(destination_file, "wb") as f: f.write(decrypted) def decode_file(self, file_path): raw_data = self.extractor.load_images() # with open("decode-test", "wb") as f: # f.write(raw_data) raw_header = raw_data[:self.get_header_length()] self.decode_header(raw_header) self.get_tag(raw_data) self.decrypt_and_save_data(raw_data, file_path)
def execute(hash): computer_list = config["hosts"] log.info("The command is: %s" % hash) enc=Encryption() if hash == "start": command="bash /home/user/startpoc/sp1_as_user.sh" elif hash == "stop": #command="killall poclbm.py" command="screen -r \n exit" else: usage() sys.exit(1) for host in computer_list: RC=BTControl(host["name"], host["user"], enc.decrypt(host["pass"]), command) RC.start()
def get(self, request): with connection.cursor() as cursor: seller_id = request.session['user_id'] cursor.execute( '''SELECT P.product_name, T.transaction_date, U.username FROM transaction T, product P, user U WHERE T.seller_id = "{}" AND P.product_id = T.product_id AND T.buyer_id = U.user_id''' .format(seller_id)) orders_result = cursor.fetchall() encryption = Encryption() orders_result = [(order[0], order[1], encryption.decrypt(order[2][2:-1].encode())) for order in orders_result] return render(request=request, template_name=self.template_name, context={'orders_result': orders_result})
def post(self, request): form = self.searchForm(request.POST) if form.is_valid(): data = form.cleaned_data with connection.cursor() as cursor: if data['search_filter'][0] == 'C': cursor.execute( '''SELECT C.cat_name, S.store_name, C.cat_descr, S.store_id, C.cat_id FROM store S, category C, store_categories SC WHERE SC.category_id IN (SELECT cat_id FROM category WHERE cat_name LIKE "%%{}%%") AND S.store_id = SC.store_id AND C.cat_id = SC.category_id'''.format( data['search_item'])) categories_result = cursor.fetchall() return render(request=request, template_name=self.buyer_template_name, context={ 'categories_result': categories_result, 'search_form': form }) elif data['search_filter'][0] == 'S': cursor.execute( '''SELECT S.store_name, S.create_date, U.username, S.store_id FROM store S, user U WHERE S.store_name LIKE "%%{}%%" AND U.user_id = S.owner_id '''.format(data['search_item'])) store_result = cursor.fetchall() encryption = Encryption() store_result = [ (store[0], store[1], encryption.decrypt(store[2][2:-1].encode()), store[3]) for store in store_result ] return render(request=request, template_name=self.buyer_template_name, context={ 'store_result': store_result, 'search_form': form }) else: cursor.execute( '''SELECT P.product_name, P.product_specs, P.product_price, P.number_in_stock, S.store_name, C.cat_name, P.product_id FROM product P, store_categories SC, store S, category C WHERE P.product_name LIKE "%%{}%%" AND C.cat_id = P.category_id AND SC.category_id = P.category_id AND S.store_id = SC.store_id'''.format( data['search_item'])) product_result = cursor.fetchall() return render(request=request, template_name=self.buyer_template_name, context={ 'product_result': product_result, 'search_form': form })
def get_word(self): return Encryption.decrypt(self.encrypted_word)