Пример #1
0
 /**
  * initialisation and auto configuration
  */
 public static function _init()
 {
     $crypter = new Crypt_AES();
     $hasher = new Crypt_Hash('sha256');
     // load the config
     \Config::load('crypt', true);
     static::$defaults = \Config::get('crypt', array());
     // generate random crypto keys if we don't have them or they are incorrect length
     $update = false;
     foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) {
         if (empty(static::$defaults[$key]) or strlen(static::$defaults[$key]) % 4 != 0) {
             $crypto = '';
             for ($i = 0; $i < 8; $i++) {
                 $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff)));
             }
             static::$defaults[$key] = $crypto;
             $update = true;
         }
     }
     // update the config if needed
     if ($update === true) {
         try {
             \Config::save('crypt', static::$defaults);
         } catch (\FileAccessException $e) {
             // failed to write the config file, inform the user
             echo \View::forge('errors/crypt_keys', array('keys' => static::$defaults));
             die;
         }
     }
 }
Пример #2
0
 public static function _init()
 {
     static::$crypter = new Crypt_AES();
     static::$hasher = new Crypt_Hash('sha256');
     // load the config
     \Config::load('crypt', true);
     static::$config = \Config::get('crypt', array());
     // generate random crypto keys if we don't have them or they are incorrect length
     $update = false;
     foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) {
         if (empty(static::$config[$key]) or strlen(static::$config[$key]) % 4 != 0) {
             $crypto = '';
             for ($i = 0; $i < 8; $i++) {
                 $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff)));
             }
             static::$config[$key] = $crypto;
             $update = true;
         }
     }
     // update the config if needed
     if ($update === true) {
         // load the file config
         \Config::load('file', true);
         try {
             \Config::save('crypt', static::$config);
             chmod(APPPATH . 'config' . DS . 'crypt.php', \Config::get('file.chmod.files', 0666));
         } catch (\FileAccessException $e) {
             // failed to write the config file, inform the user
             echo \View::forge('errors/crypt_keys', array('keys' => static::$config));
             die;
         }
     }
     static::$crypter->enableContinuousBuffer();
     static::$hasher->setKey(static::safe_b64decode(static::$config['crypto_hmac']));
 }
Пример #3
0
 public static function _init()
 {
     static::$crypter = new Crypt_AES();
     static::$hasher = new Crypt_Hash('sha256');
     // load the config
     \Config::load('crypt', true);
     static::$config = \Config::get('crypt', array());
     // generate random crypto keys if we don't have them or they are incorrect length
     $update = false;
     foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) {
         if (empty(static::$config[$key]) || strlen(static::$config[$key]) % 4 != 0) {
             $crypto = '';
             for ($i = 0; $i < 8; $i++) {
                 $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff)));
             }
             static::$config[$key] = $crypto;
             $update = true;
         }
     }
     // update the config if needed
     if ($update === true) {
         try {
             \Config::save('crypt', static::$config);
         } catch (\File_Exception $e) {
             throw new \Exception('Crypt keys are invalid or missing, and app/config/crypt.php could not be written.');
         }
     }
     static::$crypter->enableContinuousBuffer();
     static::$hasher->setKey(static::safe_b64decode(static::$config['crypto_hmac']));
 }