def decryptFile(self, path, fileObj): """Check for encryption and decrypt the fileObj if needed. Return a tuple of the file object and True if it was encrypted. Return None for the file object if the user cancels. Arguments: path -- the path name for reference fileObj -- the file object to check and decrypt """ if fileObj.read(len(encryptPrefix)) != encryptPrefix: fileObj.seek(0) return (fileObj, False) while True: password = self.passwords.get(path, '') if not password: dialog = miscdialogs.PasswordDialog( False, os.path.basename(path), QtGui.QApplication.activeWindow()) if dialog.exec_() != QtGui.QDialog.Accepted: fileObj.close() return (None, True) password = dialog.password if miscdialogs.PasswordDialog.remember: self.passwords[path] = password try: text = p3.p3_decrypt(fileObj.read(), password.encode()) fileIO = io.BytesIO(text) fileIO.name = path return (fileIO, True) except p3.CryptError: try: del self.passwords[path] except KeyError: pass
def decryptFile(self, path, fileObj): """Check for encryption and decrypt the fileObj if needed. Return a tuple of the file object and True if it was encrypted. Return None for the file object if the user cancels. Arguments: path -- the path name for reference fileObj -- the file object to check and decrypt """ if fileObj.read(len(encryptPrefix)) != encryptPrefix: fileObj.seek(0) return (fileObj, False) while True: password = self.passwords.get(path, '') if not password: dialog = miscdialogs.PasswordDialog(False, os.path.basename(path), QtGui.QApplication. activeWindow()) if dialog.exec_() != QtGui.QDialog.Accepted: fileObj.close() return (None, True) password = dialog.password if miscdialogs.PasswordDialog.remember: self.passwords[path] = password try: text = p3.p3_decrypt(fileObj.read(), password.encode()) fileIO = io.BytesIO(text) fileIO.name = path return (fileIO, True) except p3.CryptError: try: del self.passwords[path] except KeyError: pass
def protect_value(self, value, mode=0): if mode == 0: # encrypt if crypt != None and self._secretKey != None: cipher = crypt.p3_encrypt(value, self._secretKey) return base64.b64encode(cipher) elif self._hideData is True: return base64.b64encode(value) else: # decrypt if crypt != None and self._secretKey != None: cipher = base64.b64decode(value) return crypt.p3_decrypt(cipher, self._secretKey) elif self._hideData is True: return base64.b64decode(value) return value
def protect_value(self, value, mode=0): if mode == 0: # encrypt if crypt != None and self._secretKey != None : cipher = crypt.p3_encrypt(value, self._secretKey) return base64.b64encode(cipher) elif self._hideData is True: return base64.b64encode(value) else: # decrypt if crypt != None and self._secretKey != None : cipher = base64.b64decode(value) return crypt.p3_decrypt(cipher, self._secretKey) elif self._hideData is True: return base64.b64decode(value) return value
def decryptFile(self, fileObj): """Decrypt file if was encrypted""" name = fileObj.name prefix = fileObj.read(len(encryptPrefix)) self.encryptFile = prefix == encryptPrefix if self.encryptFile: password = TreeDoc.passwordDict.get(fileObj.name, '') if not password: fileObj.close() raise PasswordError, 'Missing password' try: text = p3.p3_decrypt(fileObj.read(), password) except p3.CryptError: fileObj.close() raise PasswordError, 'Incorrect password' fileObj.close() fileObj = StringIO.StringIO(text) fileObj.name = name else: fileObj.seek(0) return fileObj
def decryptFile(self, fileObj): """Check for encryption and decrypt the fileObj if needed. Return a tuple of the file object and True if it was encrypted. Return None for the file object if the user cancels. Arguments: fileObj -- the file object to check and decrypt """ if fileObj.read(len(encryptPrefix)) != encryptPrefix: fileObj.seek(0) return (fileObj, False) fileContents = fileObj.read() fileName = fileObj.name fileObj.close() while True: pathObj = pathlib.Path(fileName) password = self.passwords.get(pathObj, '') if not password: QApplication.restoreOverrideCursor() dialog = miscdialogs.PasswordDialog( False, pathObj.name, QApplication.activeWindow()) if dialog.exec_() != QDialog.Accepted: return (None, True) QApplication.setOverrideCursor(Qt.WaitCursor) password = dialog.password if miscdialogs.PasswordDialog.remember: self.passwords[pathObj] = password try: text = p3.p3_decrypt(fileContents, password.encode()) fileIO = io.BytesIO(text) fileIO.name = fileName return (fileIO, True) except p3.CryptError: try: del self.passwords[pathObj] except KeyError: pass
def protect_value(self, value, mode=0, section=None): if self._secretSections is not None and section is not None: for s in self._secretSections: if section.startswith(s): break else: return value if mode == 0: # encrypt if crypt != None and self._secretKey != None: cipher = crypt.p3_encrypt(value, self._secretKey) return base64.b64encode(cipher) elif self._hideData is True: return base64.b64encode(value) else: # decrypt if crypt != None and self._secretKey != None: cipher = base64.b64decode(value) return crypt.p3_decrypt(cipher, self._secretKey) elif self._hideData is True: return base64.b64decode(value) return value
def protect_value(self, value, mode=0, section=None): if self._secretSections is not None and section is not None: for s in self._secretSections: if section.startswith(s): break else: return value if mode == 0: # encrypt if crypt != None and self._secretKey != None : cipher = crypt.p3_encrypt(value, self._secretKey) return base64.b64encode(cipher) elif self._hideData is True: return base64.b64encode(value) else: # decrypt if crypt != None and self._secretKey != None : cipher = base64.b64decode(value) return crypt.p3_decrypt(cipher, self._secretKey) elif self._hideData is True: return base64.b64decode(value) return value
def decrypt(code): """ decrypts url-safe string to dictinoary """ return QueryDict(p3_decrypt(b64decode(str(code), B64_ALTCHARS), settings.SECRET_KEY))
def getplaintextpassword(self): return p3.p3_decrypt(self.__passwordhash,self.escrow) def getprivileges(self): return self.__privileges