def setpassword(self,passwd): if passwd: string = self.userid+passwd if type(string) is unicode: string=string.encode("UTF-8") self.__passwordhash=p3.p3_encrypt(string,self.escrow) else: self.__passwordhash=None
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 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 writeFile(self, fileRef, updateInfo=True): """Write file - raises IOError on failure""" lines = [u'<?xml version="1.0" encoding="utf-8" ?>'] if self.xlstLink: lines.append(u'<?%s?>' % self.xlstLink) lines.extend(self.root.branchXml([], True)) text = '\n'.join(lines).encode('utf-8') try: f = self.getWriteFileObj(fileRef, self.compressFile) except IOError: print 'Error - could not write file' raise filePath = unicode(f.name, sys.getfilesystemencoding()) if self.encryptFile: key = filePath.encode(sys.getfilesystemencoding()) password = TreeDoc.passwordDict.get(key, '') if not password: if key.endswith('~'): # for auto-save filename password = TreeDoc.passwordDict.get(key[:-1], '') if not password: raise PasswordError, 'Missing password' text = encryptPrefix + p3.p3_encrypt(text, password) try: f.write(text) except IOError: print 'Error - could not write file', \ filePath.encode(globalref.localTextEncoding) raise f.close() if filePath.endswith('.gz'): self.compressFile = True if updateInfo: self.modified = False self.tlVersion = __version__ self.fileName = filePath self.fileInfoFormat.updateFileInfo()
def encrypt(d): """ encrypts dictionary to url-safe string """ return b64encode(p3_encrypt(urlencode(d), settings.SECRET_KEY), B64_ALTCHARS)
def checkPassword(self, password): string = self.userid+password if type(string) is unicode: string=string.encode("UTF-8") return p3.p3_encrypt(string,self.escrow) == self.__passwordhash