public function setCrypt() { $this->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CFB); $crypt->setKey('vJ4RIGAGg6vJ9lAD'); // Используйте свой собственный ключ! return $crypt; }); }
protected function crypt() { //加密服务 $config = $this->_config; $this->_di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->crypt->key); return $crypt; }); }
/** * Initializes viewer */ public function register() { $di = $this->getDi(); $key = $this->_config->application->crypt->key; $di->set('crypt', function () use($key) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($key); return $crypt; }); }
protected function registerDatastore() { $this->di->setShared('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); $this->di->set('db', function () { $env = $this->di->get('env')->database; $conf = array('host' => $env->host, 'username' => $env->username, 'password' => $env->password, 'dbname' => $env->dbname); $adapter = new \Phalcon\Db\Adapter\Pdo\Mysql($conf); return $adapter; }); $this->di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setKey('very-secret-key'); return $crypt; }); }
/** * @requires extension mcrypt */ public function testEncryptBase64() { $crypt = new \Phalcon\Crypt(); $crypt->setPadding(\Phalcon\Crypt::PADDING_ANSI_X_923); $key = substr('phalcon notice 13123123', 0, 16); $text = 'https://github.com/phalcon/cphalcon/issues?state=open'; $encrypted = $crypt->encryptBase64($text, substr($key, 0, 16)); $actual = $crypt->decryptBase64($encrypted, $key); $this->assertEquals($actual, $text); $encrypted = $crypt->encryptBase64($text, $key, TRUE); $actual = $crypt->decryptBase64($encrypted, $key, TRUE); $this->assertEquals($actual, $text); }
public function testPadding() { $texts = array(); $key = '0123456789ABCDEF0123456789ABCDEF'; $modes = array('ecb', 'cbc', 'cfb'); $pads = array(\Phalcon\Crypt::PADDING_ANSI_X_923, \Phalcon\Crypt::PADDING_PKCS7, \Phalcon\Crypt::PADDING_ISO_10126, \Phalcon\Crypt::PADDING_ISO_IEC_7816_4, \Phalcon\Crypt::PADDING_ZERO, \Phalcon\Crypt::PADDING_SPACE); for ($i = 1; $i < 128; ++$i) { $texts[] = str_repeat('A', $i); } $crypt = new \Phalcon\Crypt(); $crypt->setCipher(MCRYPT_RIJNDAEL_256)->setKey($key); foreach ($pads as $padding) { $crypt->setPadding($padding); foreach ($modes as $mode) { $crypt->setMode($mode); foreach ($texts as $text) { $encrypted = $crypt->encrypt($text); $actual = $crypt->decrypt($encrypted); $this->assertEquals($text, $actual); } } } }
<?php //Create an instance $crypt = new Phalcon\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypt = $crypt->encryptBase64($text, $key); echo $crypt->decryptBase64($text, $key);
/** * Return decrypt password * * @return string */ public function getDecryptValue() { //Create an instance $crypt = new \Phalcon\Crypt(); $crypt->setCipher($this->_cryptType); $key = \Engine\Tools\String::generateStringTemplate($this->_keyTemplate, $this->_form->getData(), '{', '}'); $value = $this->_value; return $crypt->decryptBase64($value, $key); }
/** * Set the crypt service * * @return void */ protected function crypt() { $config = $this->_config; $this->_di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->crypt->key); $crypt->setPadding(\Phalcon\Crypt::PADDING_ZERO); return $crypt; }); }
return $navigation; }); /** * URL */ $di->set('url', function () { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri('/'); $url->setStaticBaseUri('/'); return $url; }); /** * Encryption */ $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->encryption->key); return $crypt; }); /** * Cookie */ $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); /** * Database */ $di->set('mongo', function () use($config) {
* User: Admin * Date: 2015/1/15 * Time: 11:25 */ use Phalcon\DI\FactoryDefault, Phalcon\Mvc\View, Phalcon\Mvc\Url as UrlResolver, Phalcon\Mvc\Model\MetaData\Files as MetaDataFiles, Phalcon\Mvc\Model\MetaData\Memory as MetaDataMemory, Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter, Phalcon\Events\Manager as EventsManager, Phalcon\Queue\Beanstalk, Phalcon\Logger, Phalcon\Logger\Adapter\File as FileLogger; /** * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new FactoryDefault(); //inject config $di->set('config', $config, true); /** * set crypt, 在cookies使用时候可以进行加密 */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); /** * 别用PADDING_DEFAULT影响cookies的取值 */ $crypt->setPadding(\Phalcon\Crypt::PADDING_ZERO); $crypt->setKey('?.aX/^~j1V$#1dj7'); // crypt string 必须为 16 , 24 ,32 三种长度 return $crypt; }); /** * 设置cookies和加密模式 */ $di->setShared('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); // $cookies->useEncryption(false); //如果为true则使用下面的crypt加密 , 如果使用加密那速度非常慢 return $cookies;
$di->set('resource_strings', function () use($config) { return array("config" => $config->resource_strings->path); }); $di->set('faker', function () use($config) { return array("config" => $config->faker->path); }); $di->set('lang', function () use($config) { return array("default_lang" => $config->lang->default); }); $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('secret'); //Use your own key! return $crypt; }); //Connect from DB $di->set('db', function () use($config) { return new \Phalcon\Db\Adapter\Pdo\Postgresql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name)); }); $di->set('session', function () { $session = new Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); $di->set('dispatcher', function () use($di) { $eventsManager = $di->getShared('eventsManager');
public function testYamlConfigCallback() { $config = new Phalcon\Config\Adapter\Yaml('unit-tests/config/config.yml', array('!decrypt' => function ($value) { $crypt = new Phalcon\Crypt(); return $crypt->setCipher('blowfish')->decryptBase64($value, CONFKEY); }, '!approot' => function ($value) { return APPROOT . $value; })); $this->assertTrue($this->_compareConfig($this->_config, $config)); }
}); /** * Custom mail component */ $di->set('acl', function () { return new Acl(); }); /** * Set up the security service */ $di->set('security', function () { $security = new Security(); //Set the password hashing factor to 12 rounds $security->setWorkFactor(12); return $security; }, true); /** * Set the encryption service * Key: 7}T/~"4%[GW*7O-)!"nU */ $di->setShared('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setMode(MCRYPT_MODE_CFB); $crypt->setKey('7}T/~"4%[GW*7O-)!"nU'); return $crypt; }); /** * Set global access to config, excluding db settings */ $di->set('config', $config); $di->get('auth');
} $routers = new \Phalcon\Config\Adapter\Ini('../config/router.ini'); $di = new \Phalcon\DI\FactoryDefault(); $loader = new \Phalcon\Loader(); if (!empty($config->library)) { foreach ($config->library as $name => $patch) { $namespace[$name] = '../' . $config->app->library . $patch; } } $loader->registerNamespaces($namespace); $loader->register(); $di->setShared('config', function () use($config) { return $config; }); $di->setShared('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->auth->cookie_hash); return $crypt; }); $di->setShared('cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); return $cookies; }); $di->setShared('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); //Specify routes for modules $di->setShared('router', function () use($config, $routers) { $router = new \Phalcon\Mvc\Router(false);
/** * add routing capabilities * 参考:http://docs.phalconphp.com/zh/latest/reference/routing.html#defining-routes */ $di->set('router', function () { $router = new \Phalcon\Mvc\Router(); //设置默认路由(如果同nginx,可以不用设置) $router->add("/", array('controller' => 'index', 'action' => 'index')); //Set 404 paths $router->notFound(array("controller" => "index", "action" => "route404")); return $router; }); /** * 配置对称加密服务(Setting up an Encryption service) */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); //设置全局加密密钥 $crypt->setKey('%31.1e$i86e$f!8jz'); return $crypt; }, true); /** * Redis connection is created based in the parameters defined in the configuration file */ $di->set('redis', function () use($config) { $host = $config->redis->host; $port = $config->redis->port; $redis = new Redis(); $redis->connect($host, $port); return $redis; });
$di->setShared('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true); return $cookies; }); $di->setShared('session', function () use($di) { $session = new Phalcon\Session\Adapter\Files(array('uniqueId' => 'banners')); session_name("bannerssessid"); $session->start(); return $session; }); $di->setShared('auth', function () { return new \App\Library\Auth(); }); $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->crypt->key); return $crypt; }); $di->setShared('flashSession', function () { $flash = new \Phalcon\Flash\Session(array('warning' => 'alert alert-warning', 'notice' => 'alert alert-info', 'success' => 'alert alert-success', 'error' => 'alert alert-danger', 'dismissable' => 'alert alert-dismissable')); return $flash; }); $di->set("request", 'Phalcon\\Http\\Request'); require '../app/config/vars.php'; $di->setShared('vars', $vars); if (ENVIRONMENT == ENVIRONMENT_PRODUCTION) { $di->set('modelsMetadata', function () use($config) { $metaData = new \Phalcon\Mvc\Model\MetaData\Files(array("lifetime" => 86400, "prefix" => "banners", 'metaDataDir' => APPLICATION_PATH . $config->app->cacheDir . 'metadata/')); return $metaData; });
$security = new Security(); // Set the password hashing factor to 12 rounds $security->setWorkFactor(12); return $security; }, true); /* * 设置 cookies */ $di->set('cookies', function () { $cookies = new Cookies(); $cookies->useEncryption(false); return $cookies; }, true); // $di->set('crypt', function () use($di) { $crypt = new \Phalcon\Crypt(); //这里需要设置16位密码,或者24位、32位 $crypt->setKey('myCryptKey024025'); return $crypt; }, true); /* * 设置 Flash */ $di->set('flash', function () { //使用bootstrap的css设置 $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']); return $flash; }); /* * 设置路由 * 以下的路由的设置好处是能够看清楚全部的路由信息!
}); /** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); //Register the flash service with custom CSS classes $di->set('flash', function () { return new \Phalcon\Flash\Direct(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); }); //Set up encryption key $di->set('crypt', function () use($config) { $crypt = new Phalcon\Crypt(); $crypt->setKey($config->application->encryptKey); return $crypt; }); //Dispatcher $di->set('dispatcher', function () use($di) { $eventsManager = $di->getShared('eventsManager'); $security = new Security($di); $eventsManager->attach('dispatch', $security); $dispatcher = new Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); //Load config into the di $di->set('config', $config); //Logging
} defined('SITENAME') || define('SITENAME', ucfirst($sitename)); /** * Registering a set of directories taken from the configuration file */ $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array('Lininliao\\Library' => ROOT . DS . 'library', 'Lininliao\\Models' => ROOT . DS . 'models', 'Lininliao\\Plugins' => ROOT . DS . 'plugins')); /** * Loader registe directories */ $loader->registerDirs(array(ROOT . DS . 'library', ROOT . DS . 'models', ROOT . DS . 'plugins'))->register(); /** * Set the global encryption key. */ $di->set('crypt', function () use($config) { $crypt = new \Phalcon\Crypt(); $crypt->setKey($config->cookie->crypt); return $crypt; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $db_config = $config->database[ENVIRONMENT]; return new DbAdapter(array('host' => $db_config->dbhost, 'username' => $db_config->dbusername, 'password' => $db_config->dbpassword, 'dbname' => $db_config->dbname)); }, true); /** * Start the session the first time some component request the session service */ $di->set('cookies', function () use($config) { $cookies = new \Phalcon\Http\Response\Cookies();
<?php $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('#1dj8$=dp?.ak//j1V$'); //Use your own key! return $crypt; });
public static function load(&$di, &$config) { /** * The URL component is used to generate all kind of urls in the application */ $di->set('url', function () use($config) { $url = new UrlResolver(); $url->setBaseUri($config->application->baseUri); return $url; }, true); /** * Setting up the view component */ $di->set('view', function () use($config) { $view = new View(); $view->setViewsDir($config->application->viewsDir); return $view; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { $db = new DbAdapter((array) $config->database); $db->timeout = $config->database->timeout; $db->start = time(); $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('db', function ($event, $db) { if ($event->getType() == 'beforeQuery') { $idle = time() - $db->start; if ($idle > $db->timeout) { $db->connect(); $db->start = time(); } } return true; }); return $db; }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); /** * Set encryption */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('&fhm8.2$m62$/,1@'); return $crypt; }, true); /** * Set security component to validate / generate tokens */ $di->set('secure', function () { return new SecurityComponent(); }); }
<?php $di->set('encryption', function () { $encryption = new Phalcon\Crypt(); //Set a global encryption key $encryption->setKey('311e86effdada283219971cca5ad5a19'); return $encryption; }, true);
$eventsManager->attach('dispatch', $security); $dispatcher->setEventsManager($eventsManager); return $dispatcher; }); /*//flash info in the page $di->set('flash',function () { return new Phalcon\Flash\Session(array( 'error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info' )); });*/ //cookie crypt $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('sify21'); //Use your own key! return $crypt; }); //cookie $di->set("cookies", function () { $cookies = new Phalcon\Http\Response\Cookies(); return $cookies; }); /*//generate html tags through calling functions $di->set('tag',function(){ return new Phalcon\Tag(); });*/ //Handle the request $app = new \Phalcon\Mvc\Application($di);
<?php $crypt = new Phalcon\Crypt(); $key = 'le password'; $text = 'This is a secret text'; $encrypted = $crypt->encrypt($text, $key); echo $crypt->decrypt($encrypted, $key);
return $view; }); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new DbAdapter($config->database->toArray()); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setCipher('blowfish'); $crypt->setKey('vmS"TG<'); return $crypt; }, true); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('cookie', function () { $cookies = new Cookies(); $cookies->useEncryption(true);
$volt = new VoltEngine($view, $di); $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_')); return $volt; }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php')); return $view; }, true); /** * Database connection is created based in the parameters defined in the configuration file */ $di->set('db', function () use($config) { return new DbAdapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname)); }); /** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->set('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setKey('FLK#F#apf3NKfw32'); return $crypt; });
}); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('cookies', function () { $cookies = new Phalcon\Http\Response\Cookies(); $cookies->useEncryption(false); return $cookies; }); $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('#_+//*(*&eA|;76$'); return $crypt; }); $di->set('dispatcher', function () use($di) { //Obtain the standard eventsManager from the DI $eventsManager = $di->getShared('eventsManager'); //Instantiate the Security plugin $security = new Security($di); //Listen for events produced in the dispatcher using the Security plugin $eventsManager->attach('dispatch', $security); $dispatcher = new Phalcon\Mvc\Dispatcher(); //Bind the EventsManager to the Dispatcher $dispatcher->setEventsManager($eventsManager); return $dispatcher; }, true);
/** * If the configuration specify the use of metadata adapter use it or use memory otherwise */ $di->set('modelsMetadata', function () { return new MetaDataAdapter(); }); /** * Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); //TODO set Expire infinity return $session; }); /** * set flash component */ $di->setShared('flashSession', function () use($di) { $di->getShared('session'); $flashSession = new \Phalcon\Flash\Session(array('error' => 'alert alert-error', 'success' => 'alert alert-success', 'notice' => 'alert alert-info')); return $flashSession; }); /** * Set Crypt Component use to Cookies */ $di->set('crypt', function () { $crypt = new Phalcon\Crypt(); $crypt->setKey('car_mate_local_favour'); return $crypt; });
}); /** * Component flashSession (Session keep flash messages). */ $di->setShared('flash', function () { $flash = new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info']); return $flash; }); $di->setShared('cookies', function () { $cookies = new \Phalcon\Http\Response\Cookies(); $cookies->useEncryption(true); return $cookies; }); // Default component to crypt cookies values $di->set('crypt', function () { $crypt = new \Phalcon\Crypt(); $crypt->setKey($this->_config->cookieCryptKey); return $crypt; }); // Setup Hansel & Gretel breadcrumbs )) $di->set('breadcrumbs', function () { return new \Plugins\Breadcrumbs\Breadcrumbs(); }); // Component Navigation. Manage site navigation $di->setShared('navigation', function () { require_once APP_PATH . '/config/navigation.php'; if (isset($navigation[self::MODULE])) { return new \Libraries\Navigation\Navigation(new \Phalcon\Config($navigation[self::MODULE])); } }); // If the configuration specify the use of metadata adapter use it or use memory otherwise