/** * Tests Crypt->setKey() */ public function testSetKey() { // Set new key $newkey = 'gjhfdbhTGFJUGFDbvfdJHGFNcxfdsgDHVCNBfdsgjhgfNfdhgfdhd'; $this->crypt->setKey($newkey); // Reset to old key $this->crypt->setKey(self::KEY); unset($newkey); }
/** * constructor function * * @param string $obfuscatedFilePostfix */ public function __construct($key = '', $obfuscatedFilePostfix = "") { $this->level = ''; $this->key = $key; if (trim($obfuscatedFilePostfix) != "") { $this->obfuscatedFilePostfix = $obfuscatedFilePostfix; } Crypt::setKey($this->key); }
/** * 输出验证码 */ public function captcha() { $builder = new CaptchaBuilder(); $builder->build(); $phrase = $builder->getPhrase(); Crypt::setKey(Config::get('app.cookie_key')); $phrase_new = Crypt::encrypt($phrase); Session::flash('__captcha', $phrase_new); header("Cache-Control: no-cache, must-revalidate"); header('Content-Type: image/jpeg'); $builder->output(); exit; }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('demographics', function (Blueprint $table) { $table->string('creditcard_key', 255)->nullable()->default(''); }); $query = DB::table('demographics')->where(function ($query_array1) { $query_array1->where('creditcard_number', '!=', '')->orWhereNotNull('creditcard_number'); })->get(); if ($query) { foreach ($query as $row) { $key = MD5(microtime()); Crypt::setKey($key); $new = Crypt::encrypt($row->creditcard_number); $data = array('creditcard_key' => $key, 'creditcard_number' => $new); DB::table('demographics')->where('pid', '=', $row->pid)->update($data); } } }
<?php require_once '../Crypt.php'; $crypt = new Crypt(); $crypt->setKey('YOUR CYPHER KEY'); $crypt->setComplexTypes(TRUE); $crypt->setData('cryptPHP#bWOXEusBnyDHRuNY+zAyqOWpYLPkmSMJ#tdcvQqIxylC3bNuxFQ1GUIyKN0eO8HF/2JsQJG2GhkovgNEmQDTYLELIwNwoK5vmgaErww4CGslPDx1F2ZS7uVqMJcNnD4tp7XAKzCCqmWZNw+1mWRuf#3089b5eda40c7a40171666c6fb2694077b03de2d'); var_dump($crypt->decrypt());
public function postSaveCreditcard() { $data = array(); $query = DB::table('demographics')->where('pid', '=', Session::get('pid'))->first(); if ($query->creditcard_key == '') { $key = MD5(microtime()); $data['creditcard_key'] = $key; } else { $key = $query->creditcard_key; } Crypt::setKey($key); $data['creditcard_number'] = Crypt::encrypt(Input::get('creditcard_number')); Crypt::setKey('YourSecretKey!!!'); $data['creditcard_expiration'] = Input::get('creditcard_expiration'); $data['creditcard_type'] = Input::get('creditcard_type'); DB::table('demographics')->where('pid', '=', Session::get('pid'))->update($data); $this->audit('Update'); echo "Credit Card Information Updated!"; }
* Error handler */ set_error_handler(function ($errno, $errstr, $errfile, $errline) use($di) { if (!(error_reporting() & $errno)) { return; } $di->getFlash()->error($errstr); $di->getLogger()->log($errstr . ' ' . $errfile . ':' . $errline, Phalcon\Logger::ERROR); return true; }); /** * Encryption service */ $di->set('crypt', function () use($config) { $crypt = new Crypt(); $crypt->setKey('1234'); return $crypt; }); /** * Handle the request */ $application = new \Phalcon\Mvc\Application(); $application->setDI($di); /** * Register application modules */ //$application->registerModules(require __dir__ . '/../common/config/modules.php'); // Register the installed modules $application->registerModules(array('frontend' => array('className' => 'Frontend\\Module', 'path' => '../apps/frontend/Module.php'), 'backend' => array('className' => 'Backend\\Module', 'path' => '../apps/backend/Module.php'))); echo $application->handle()->getContent(); } catch (Phalcon\Exception $e) {