def export_encrypted_recovery(self, gateway, password): settings = gateway.get_settings(include_rootcap=True) data = json.dumps(settings) self.progress = QProgressDialog("Encrypting...", None, 0, 100) self.progress.show() self.animation = QPropertyAnimation(self.progress, b'value') self.animation.setDuration(5000) # XXX self.animation.setStartValue(0) self.animation.setEndValue(99) self.animation.start() self.crypter = Crypter(data.encode(), password.encode()) self.crypter_thread = QThread() self.crypter.moveToThread(self.crypter_thread) self.crypter.succeeded.connect(self.animation.stop) self.crypter.succeeded.connect(self.progress.close) self.crypter.succeeded.connect(self.on_encryption_succeeded) self.crypter.failed.connect(self.animation.stop) self.crypter.failed.connect(self.progress.close) self.crypter.failed.connect(self.on_encryption_failed) self.crypter_thread.started.connect(self.crypter.encrypt) self.crypter_thread.start() dest, _ = QFileDialog.getSaveFileName( self, "Select a destination", os.path.join(os.path.expanduser('~'), gateway.name + ' Recovery Key.json.encrypted')) if not dest: return if self.export_data: with open(dest, 'wb') as f: f.write(self.export_data) self.confirm_export(dest) self.export_data = None else: self.export_dest = dest
def _decrypt_content(self, data, password): logging.debug("Trying to decrypt %s...", self.filepath) self.progress = QProgressDialog( "Trying to decrypt {}...".format(os.path.basename(self.filepath)), None, 0, 100, ) self.progress.show() self.animation = QPropertyAnimation(self.progress, b"value") self.animation.setDuration(6000) # XXX self.animation.setStartValue(0) self.animation.setEndValue(99) self.animation.start() self.crypter = Crypter(data, password.encode()) self.crypter_thread = QThread() self.crypter.moveToThread(self.crypter_thread) self.crypter.succeeded.connect(self.animation.stop) self.crypter.succeeded.connect(self.progress.close) self.crypter.succeeded.connect(self._on_decryption_succeeded) self.crypter.failed.connect(self.animation.stop) self.crypter.failed.connect(self.progress.close) self.crypter.failed.connect(self._on_decryption_failed) self.crypter_thread.started.connect(self.crypter.decrypt) self.crypter_thread.start()
def decrypt_content(self, data, password): self.progress = QProgressDialog("Trying to decrypt...", None, 0, 100) self.progress.show() self.animation = QPropertyAnimation(self.progress, b'value') self.animation.setDuration(5000) # XXX self.animation.setStartValue(0) self.animation.setEndValue(99) self.animation.start() self.crypter = Crypter(data, password.encode()) self.crypter_thread = QThread() self.crypter.moveToThread(self.crypter_thread) self.crypter.succeeded.connect(self.animation.stop) self.crypter.succeeded.connect(self.progress.close) self.crypter.succeeded.connect(self.on_decryption_succeeded) self.crypter.failed.connect(self.animation.stop) self.crypter.failed.connect(self.progress.close) self.crypter.failed.connect(self.on_decryption_failed) self.crypter_thread.started.connect(self.crypter.decrypt) self.crypter_thread.start()
def _export_encrypted_recovery(self, gateway, password): settings = gateway.get_settings(include_rootcap=True) if gateway.use_tor: settings["hide-ip"] = True data = json.dumps(settings) self.progress = QProgressDialog("Encrypting...", None, 0, 100) self.progress.show() self.animation = QPropertyAnimation(self.progress, b"value") self.animation.setDuration(6000) # XXX self.animation.setStartValue(0) self.animation.setEndValue(99) self.animation.start() self.crypter = Crypter(data.encode(), password.encode()) self.crypter_thread = QThread() self.crypter.moveToThread(self.crypter_thread) self.crypter.succeeded.connect(self.animation.stop) self.crypter.succeeded.connect(self.progress.close) self.crypter.succeeded.connect(self._on_encryption_succeeded) self.crypter.failed.connect(self.animation.stop) self.crypter.failed.connect(self.progress.close) self.crypter.failed.connect(self._on_encryption_failed) self.crypter_thread.started.connect(self.crypter.encrypt) self.crypter_thread.start() dest, _ = QFileDialog.getSaveFileName( self.parent, "Select a destination", os.path.join( os.path.expanduser("~"), gateway.name + " Recovery Key.json.encrypted", ), ) if not dest: return if self.ciphertext: with atomic_write(dest, mode="wb", overwrite=True) as f: f.write(self.ciphertext) self.done.emit(dest) self.ciphertext = None else: self.filepath = dest
def export_encrypted_recovery(self, gateway, password): settings = gateway.get_settings(include_rootcap=True) data = json.dumps(settings) self.crypter = Crypter(data.encode(), password.encode()) self.crypter_thread = QThread() self.crypter.moveToThread(self.crypter_thread) self.crypter.succeeded.connect(self.on_encryption_succeeded) self.crypter.failed.connect(self.on_encryption_failed) self.crypter_thread.started.connect(self.crypter.encrypt) self.crypter_thread.start() dest, _ = QFileDialog.getSaveFileName( self, "Select a destination", os.path.join(os.path.expanduser('~'), gateway.name + ' Recovery Key.json.encrypted')) if not dest: return if self.export_data: with open(dest, 'wb') as f: f.write(self.export_data) self.confirm_export(dest) self.export_data = None else: self.export_dest = dest
def crypter(): return Crypter(b"data", b"password")
def crypter(): return Crypter(b'data', b'password')