/** * Encrypts your mail settings * * @param $username * * @param $password * * @param null $callback * * @return bool */ public static function EncryptMailSettings($username, $password, $callback = null) { if (FileMethods::FileExists(PathFinder::RealPath('Json/encrypted/mailer_settings.json'))) { /** * We already have settings! */ return false; } /** * The decryption key */ $key = Random::RandomMD5(); /** * If not, lets create an array, encrypting each value */ $array = ['decryption_key' => $key, 'mailer_settings' => ['username' => Encryption::EncryptString($username, $key), 'password' => Encryption::EncryptString($password, $key)]]; /** * Write file */ JsonWriter::PathWrite('Json/encrypted/mailer_settings.json', $array); /** * Is there a callback? */ if ($callback != null) { call_user_func($callback); } /** * Return true! */ return true; }
/** * Exactly the same as the above, except this one decrypts the mail settings! * * @return array|null */ public static function DecryptMailerSettings() { if (FileMethods::FileExists(PathFinder::RealPath('Json/encrypted/mailer_settings.json'))) { $return = array(); /** * Reads our settings */ $read_settings = JsonReader::Read('Json/encrypted/mailer_settings.json'); /** * Loop */ foreach ($read_settings['mailer_settings'] as $key => $value) { /** * Lets first get the vector */ $vector = $value['vector']; /** * Then, lets decrypt! */ $return[$key] = Encryption::DecryptString($value['encrypted_string'], $read_settings['decryption_key'], $vector); } /** * Return this array */ return $return; } /** * If no files could be found */ return null; }
/** * Encrypts and writes our database settings to file * * @param $username * * @param $password * * @param $location * * @param $address * * @param $callback * * @return bool|null */ public function InitializeDatabase($username, $password, $location, $address, $callback = null) { /** * We first check if we already have settings */ if (FileMethods::FileExists(PathFinder::RealPath('Json/encrypted/database_settings.json'))) { /** * We already have settings! */ return false; } /** * The decryption key */ $key = Random::RandomMD5(); /** * If not, lets create an array, encrypting each value */ $array = ['decryption_key' => $key, 'database_settings' => ['username' => Encryption::EncryptString($username, $key), 'password' => Encryption::EncryptString($password, $key), 'database' => Encryption::EncryptString($location, $key), 'host' => Encryption::EncryptString($address, $key)]]; /** * Write file */ JsonWriter::PathWrite('Json/encrypted/database_settings.json', $array); /** * Is there a callback? */ if ($callback != null) { call_user_func($callback); } /** * Return true! */ return true; }