Exemplo n.º 1
0
 def pipeline(fd_in: BinaryIO, op1: Callable[[bytes], bytes],
              op2: Callable[[bytes], bytes], fd_out: BinaryIO):
     progress = Progress.get_instance()
     for chunk in iter(partial(fd_in.read, buffer_size), b''):
         progress.update(len(chunk))
         chunk = op1(chunk)
         chunk = op2(chunk)
         fd_out.write(chunk)
         progress.print()
Exemplo n.º 2
0
    def __init__(self, password, f_in_path):
        self.__progress = Progress.get_instance()
        self.__fd_in = open(f_in_path, 'rb')

        meta = self.__read_meta()
        key, _ = derive_key(password, meta['salt'])
        self.__decryptor = self.__aes_decryptor(key, meta['iv'])

        self.__f_out_ext = self.__decrypt_ext(meta['c_ext'])
        self.__f_out_path = replace_file_ext(f_in_path, self.__f_out_ext)
Exemplo n.º 3
0
def _read_header(f_in_path: Path) -> Dict[str, bytes]:
	header = b''
	header_len = 48
	with open(f_in_path, 'rb') as fd_in:
		header = fd_in.read(header_len)
	progress = Progress.get_instance()
	progress.update(header_len)
	return {
		'iv': header[0:16],
		'salt': header[16:32],
		'cipher_ext': header[32:64]
	}
	
Exemplo n.º 4
0
    def __init__(self, key, salt, f_in_path):
        self.__f_in_path = f_in_path

        iv = urandom(16)  # Generate random iv per file
        self.__encryptor = self.__aes_encryptor(key, iv)

        meta = {'iv': None, 'salt': None, 'c_ext': None}
        meta['salt'] = salt
        meta['iv'] = iv
        ext = file_ext(f_in_path)
        meta['c_ext'] = self.__encrypt_ext(ext)

        self.__fd_out = open(replace_file_ext(f_in_path, 'kpk'), 'wb')
        self.__write_meta(meta)

        self.__progress = Progress.get_instance()