def _encrypt_data(self): """Serialize, encipher, and base64 the session dict""" if self.encrypt_key: nonce = b64encode(os.urandom(40))[:8] encrypt_key = crypto.generateCryptoKeys(self.encrypt_key, self.validate_key + nonce, 1) data = pickle.dumps(self.copy(), 2) return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key)) else: data = pickle.dumps(self.copy(), 2) return b64encode(data)
def _encrypt_data(self): """Serialize, encipher, and base64 the session dict""" if self.encrypt_key: nonce = b64encode(os.urandom(40))[:8] encrypt_key = crypto.generateCryptoKeys(self.encrypt_key, self.validate_key + nonce, 1) data = pickle.dumps(self.copy(), 2) return nonce + b64encode(crypto.aesEncrypt(data, encrypt_key)) else: data = pickle.dumps(self.copy(), 2) return b64encode(data)
def _decrypt_data(self): """Bas64, decipher, then un-serialize the data for the session dict""" if self.encrypt_key: nonce = self.cookie[self.key].value[:8] encrypt_key = crypto.generateCryptoKeys(self.encrypt_key, self.validate_key + nonce, 1) payload = b64decode(self.cookie[self.key].value[8:]) data = crypto.aesDecrypt(payload, encrypt_key) return pickle.loads(data) else: data = b64decode(self.cookie[self.key].value) return pickle.loads(data)
def _decrypt_data(self): """Bas64, decipher, then un-serialize the data for the session dict""" if self.encrypt_key: nonce = self.cookie[self.key].value[:8] encrypt_key = crypto.generateCryptoKeys(self.encrypt_key, self.validate_key + nonce, 1) payload = b64decode(self.cookie[self.key].value[8:]) data = crypto.aesDecrypt(payload, encrypt_key) return pickle.loads(data) else: data = b64decode(self.cookie[self.key].value) return pickle.loads(data)