/** * Performs environmental set-up similar to that in {@link ApplicationConfigBehavior} */ public static function setUpAppEnvironment($full = false) { // uses a specific key/iv for unit testing foreach (array('iv', 'key') as $ext) { $file = Yii::app()->basePath . "/config/encryption.{$ext}"; $testFile = Yii::app()->basePath . "/tests/data/encryption/encryption.{$ext}"; self::${$ext} = $file; if (file_exists($file)) { rename($file, "{$file}.bak"); copy($testFile, $file); } } EncryptedFieldsBehavior::setup(self::$key, self::$iv); if ($full) { self::setUpAppEnvironment2(); } }
/** * Instantiates the encryption utility object so that components depending * on {@link EncryptedFieldsBehavior} can also be instantiated. */ public function cryptInit() { if (!$this->_cryptInit) { $key = $this->owner->basePath . '/config/encryption.key'; $iv = $this->owner->basePath . '/config/encryption.iv'; if (extension_loaded('openssl') && extension_loaded('mcrypt') && file_exists($key) && file_exists($iv)) { EncryptedFieldsBehavior::setup($key, $iv); } else { // Use unsafe method with encryption EncryptedFieldsBehavior::setupUnsafe(); } } }