def _decrypt_file(instructions, file_name): fp = open(file_name, 'r') lines = fp.readlines() fp.close() need_to_write = False for i in range(len(lines)): line = lines[i] if line.find('='): need_to_write = True tokens = line.split() for t in tokens: if t.endswith('='): plaintext = CPSecurity.decrypt( instructions['encryption_key'], t) if plaintext is None: print('error: Incorrect Decryption Key') sys.exit(-1) lines[i] = line.replace(t, plaintext) if need_to_write: print('Updating %s' % file_name) fp = open(file_name, 'w') for line in lines: fp.write(line) fp.close()
def _validate_encryption_key(self, secret): value = self._get_encrypted_validator() if value: property_value = 'encryption_key_checker' value = CPSecurity.decrypt(secret, value) if value == property_value: return True return False
def _migrate_keys(self, prev_encryption_key, encryption_key): state_persistor = StatePersistor( self._models, self._controllers, persistence_file='private_data.yml') all_private_data = state_persistor.recall_info() for k, v in six.iteritems(all_private_data): if k == 'encryption_key_checker': continue if not self._was_persisted_value_encrypted(k): continue v = CPSecurity.decrypt(prev_encryption_key, v) v = CPSecurity.encrypt(encryption_key, v) info = {k: v} state_persistor.persist_info(info)
def _decrypt_file_contents(self, file_name): fp = open(file_name, 'r') lines = fp.readlines() fp.close() need_to_write = False for i in range(len(lines)): line = lines[i] if line.find('='): tokens = line.split() for t in tokens: if t.endswith('='): plaintext = CPSecurity.decrypt( self._instructions['encryption_key'], t) if plaintext is not None: lines[i] = line.replace(t, plaintext) need_to_write = True if need_to_write: fp = open(file_name, 'w') for line in lines: fp.write(line) fp.close()
def decrypt_value(value, instructions): return CPSecurity.decrypt(instructions['encryption_key'], value)