当前位置: 首页>>代码示例>>PHP>>正文


PHP Security::encrypt方法代码示例

本文整理汇总了PHP中Cake\Utility\Security::encrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::encrypt方法的具体用法?PHP Security::encrypt怎么用?PHP Security::encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Utility\Security的用法示例。


在下文中一共展示了Security::encrypt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getTokenForUser

 /**
  * Generates a serialized, encrypted and base64-encoded for identifying a user,
  * usually for using it in an URL
  *
  * @param User $user The user Entity
  * @param int $validForSeconds how long the token should be valid
  * @param array $additionalData Optional additional data for storage in the encrypted token
  * @return string
  */
 public function getTokenForUser(User $user, $validForSeconds = null, array $additionalData = [])
 {
     $tokenData = ['user_id' => $user->id, 'generated' => time(), 'validForSeconds' => $validForSeconds, 'additionalData' => $additionalData];
     $tokenDataString = serialize($tokenData);
     $encrypted = Security::encrypt($tokenDataString, Configure::read('Security.cryptKey'));
     return base64_encode($encrypted);
 }
开发者ID:codekanzlei,项目名称:cake-cktools,代码行数:16,代码来源:UserToken.php

示例2: marshal

 /**
  * Marshalls request data into PHP strings.
  *
  * @param mixed $value The value to convert.
  * @return mixed Converted value.
  */
 public function marshal($value)
 {
     if ($value === null) {
         return $value;
     }
     return base64_encode(Security::encrypt($value, Configure::read('Security.key')));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:13,代码来源:EncryptedSecurityType.php

示例3: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->type = Type::build('encryptedsecurity');
     $this->driver = $this->getMockBuilder('Cake\\Database\\Driver')->getMock();
     $this->crypted = base64_encode(Security::encrypt('string', Configure::read('Security.key')));
 }
开发者ID:Xety,项目名称:Xeta,代码行数:12,代码来源:EncryptedSecurityTypeTest.php

示例4: _encrypt

 /**
  * Encrypts $value using public $type method in Security class
  *
  * @param string $value Value to encrypt
  * @param string|bool $encrypt Encryption mode to use. False
  *   disabled encryption.
  * @param string|null $key Used as the security salt only in this time for tests if specified.
  * @return string Encoded values
  */
 protected function _encrypt($value, $encrypt, $key = null)
 {
     if (is_array($value)) {
         $value = $this->_implode($value);
     }
     if ($encrypt === false) {
         return $value;
     }
     $this->_checkCipher($encrypt);
     $prefix = "Q2FrZQ==.";
     $cipher = null;
     if (!isset($key)) {
         $key = $this->_getCookieEncryptionKey();
     }
     if ($encrypt === 'rijndael') {
         $cipher = Security::rijndael($value, $key, 'encrypt');
     }
     if ($encrypt === 'aes') {
         $cipher = Security::encrypt($value, $key);
     }
     return $prefix . base64_encode($cipher);
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:31,代码来源:CookieCryptTrait.php

示例5: _encrypt

 /**
  * Encrypts $value using public $type method in Security class
  *
  * @param string $value Value to encrypt
  * @param string|bool $encrypt Encryption mode to use. False
  *   disabled encryption.
  * @return string Encoded values
  */
 protected function _encrypt($value, $encrypt)
 {
     if (is_array($value)) {
         $value = $this->_implode($value);
     }
     if (!$encrypt) {
         return $value;
     }
     $this->_checkCipher($encrypt);
     $prefix = "Q2FrZQ==.";
     if ($encrypt === 'rijndael') {
         $cipher = Security::rijndael($value, $this->_config['key'], 'encrypt');
     }
     if ($encrypt === 'aes') {
         $cipher = Security::encrypt($value, $this->_config['key']);
     }
     return $prefix . base64_encode($cipher);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:26,代码来源:CookieComponent.php

示例6: _encrypt

 /**
  * encrypt method
  *
  * @param array|string $value
  * @return string
  */
 protected function _encrypt($value)
 {
     if (is_array($value)) {
         $value = $this->_implode($value);
     }
     return "Q2FrZQ==." . base64_encode(Security::encrypt($value, $this->Cookie->config('key')));
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:13,代码来源:CookieComponentTest.php

示例7: encrypt

 /**
  * Encrypt a value
  * @param type $value Value to be encrypted
  * @return type Encrypted value
  */
 public function encrypt($value)
 {
     return Security::encrypt($value, $this->config('key'), $this->config('salt'));
 }
开发者ID:lorenzo,项目名称:cakephp-cipher-behavior,代码行数:9,代码来源:CipherBehavior.php

示例8: _encrypt

 /**
  * Encrypt a string
  *
  * @param string $value string to encrypt
  * @return string
  */
 protected function _encrypt($value)
 {
     return base64_encode(Security::encrypt($value, $this->_encryptionKey()));
 }
开发者ID:andrej-griniuk,项目名称:cakephp-two-factor-auth,代码行数:10,代码来源:FormAuthenticate.php

示例9: testEngineEquivalence

 /**
  * Test that values encrypted with open ssl can be decrypted with mcrypt and the reverse.
  *
  * @return void
  */
 public function testEngineEquivalence()
 {
     $this->skipIf(!defined('MCRYPT_RIJNDAEL_128'), 'This needs mcrypt extension to be loaded.');
     $restore = Security::engine();
     $txt = "Obi-wan you're our only hope";
     $key = 'This is my secret key phrase it is quite long.';
     $salt = 'A tasty salt that is delicious';
     Security::engine(new Mcrypt());
     $cipher = Security::encrypt($txt, $key, $salt);
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new OpenSsl());
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new OpenSsl());
     $cipher = Security::encrypt($txt, $key, $salt);
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new Mcrypt());
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
 }
开发者ID:Slayug,项目名称:castor,代码行数:23,代码来源:SecurityTest.php

示例10: testEngineEquivalence

 /**
  * Test that values encrypted with open ssl can be decrypted with mcrypt and the reverse.
  *
  * @return void
  */
 public function testEngineEquivalence()
 {
     $restore = Security::engine();
     $txt = "Obi-wan you're our only hope";
     $key = 'This is my secret key phrase it is quite long.';
     $salt = 'A tasty salt that is delicious';
     Security::engine(new Mcrypt());
     $cipher = Security::encrypt($txt, $key, $salt);
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new OpenSsl());
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new OpenSsl());
     $cipher = Security::encrypt($txt, $key, $salt);
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
     Security::engine(new Mcrypt());
     $this->assertEquals($txt, Security::decrypt($cipher, $key, $salt));
 }
开发者ID:kk-kahle,项目名称:CI-VZ,代码行数:22,代码来源:SecurityTest.php

示例11: encrypt

 /**
  * {@inheritdoc}
  */
 public function encrypt($plain)
 {
     return Security::encrypt($plain, $this->__key);
 }
开发者ID:UseMuffin,项目名称:Crypt,代码行数:7,代码来源:DefaultStrategy.php

示例12: testEncryptDecryptFalseyData

 /**
  * Test encrypting falsey data
  *
  * @return void
  */
 public function testEncryptDecryptFalseyData()
 {
     $key = 'This is a key that is long enough to be ok.';
     $result = Security::encrypt('', $key);
     $this->assertSame('', Security::decrypt($result, $key));
     $result = Security::encrypt(false, $key);
     $this->assertSame('', Security::decrypt($result, $key));
     $result = Security::encrypt(null, $key);
     $this->assertSame('', Security::decrypt($result, $key));
     $result = Security::encrypt(0, $key);
     $this->assertSame('0', Security::decrypt($result, $key));
     $result = Security::encrypt('0', $key);
     $this->assertSame('0', Security::decrypt($result, $key));
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:19,代码来源:SecurityTest.php

示例13: login

 /**
  * Login and register page.
  *
  * @return \Cake\Network\Response|void
  */
 public function login()
 {
     //Handle Maintenances
     if (Configure::read('User.Login.enabled') === false) {
         $this->Flash->error(__("The Login action is disabled for the moment, please try again later."));
     }
     if (Configure::read('User.Register.enabled') === false && Configure::read('Site.maintenance') === false) {
         $this->Flash->error(__("The Register action is disabled for the moment, please try again later."));
     }
     if (Configure::read('Site.maintenance') === true) {
         $this->Flash->error(__("While the site is in maintenance, you can not register a new account."));
     }
     if ($this->request->is('post')) {
         $method = $this->request->data['method'] ? $this->request->data['method'] : false;
         switch ($method) {
             case "login":
                 if (Configure::read('User.Login.enabled') === false) {
                     $userRegister = $userRegister = $this->Users->newEntity($this->request->data);
                     break;
                 }
                 $userLogin = $this->Auth->identify();
                 if ($userLogin) {
                     if ($userLogin['is_deleted'] == true) {
                         $this->Flash->error(__("This account has been deleted."));
                         $userRegister = $this->Users->newEntity($this->request->data);
                         break;
                     }
                     //Check the 2FA if the user has enabled it.
                     if ($userLogin['two_factor_auth_enabled'] == true && $this->TwoFactorAuth->isAuthorized($userLogin['id']) === false) {
                         //Write the cookie
                         $cookie = base64_encode(Security::encrypt($userLogin['id'], Configure::read('Security.key')));
                         $this->Cookie->configKey('CookieTfa', ['expires' => '+1 hour', 'httpOnly' => true]);
                         $this->Cookie->write('CookieTfa', $cookie);
                         return $this->redirect(['action' => 'tfa']);
                     }
                     $this->_handleLogin($userLogin);
                     $this->Auth->setUser($userLogin);
                     $user = $this->Users->newEntity($userLogin, ['accessibleFields' => ['id' => true]]);
                     $user->isNew(false);
                     $user->last_login = new Time();
                     $user->last_login_ip = $this->request->clientIp();
                     $this->Users->save($user);
                     //Cookies.
                     $this->Cookie->configKey('CookieAuth', ['expires' => '+1 year', 'httpOnly' => true]);
                     $this->Cookie->write('CookieAuth', ['username' => $this->request->data('username'), 'password' => $this->request->data('password')]);
                     //Badge Event.
                     $this->eventManager()->attach(new Badges($this));
                     $user = new Event('Model.Users.register', $this, ['user' => $user]);
                     $this->eventManager()->dispatch($user);
                     $url = $this->Auth->redirectUrl();
                     if (substr($this->Auth->redirectUrl(), -5) == 'login') {
                         $url = ['controller' => 'pages', 'action' => 'home'];
                     }
                     return $this->redirect($url);
                 }
                 $user = $this->Users->find()->where(['username' => $this->request->data['username']])->select(['id', 'group_id', 'username', 'email'])->first();
                 if (!is_null($user)) {
                     //Users Event.
                     $this->eventManager()->attach(new Users());
                     $event = new Event('Users.login.failed', $this, ['user_id' => $user->id, 'username' => $user->username, 'group_id' => $user->group_id, 'user_ip' => $this->request->clientIp(), 'user_email' => $user->email, 'user_agent' => $this->request->header('User-Agent'), 'action' => 'user.connection.manual.failed']);
                     $this->eventManager()->dispatch($event);
                 }
                 $this->Flash->error(__("Your username or password doesn't match."));
                 $userRegister = $this->Users->newEntity($this->request->data);
                 break;
             case "register":
                 $userRegister = $this->Users->newEntity($this->request->data, ['validate' => 'create']);
                 //Handle Maintenances
                 if (Configure::read('Site.maintenance') === true || Configure::read('User.Register.enabled') === false) {
                     break;
                 }
                 $userRegister->register_ip = $this->request->clientIp();
                 $userRegister->last_login_ip = $this->request->clientIp();
                 $userRegister->last_login = new Time();
                 if ($this->Recaptcha->verify() || Configure::read('Recaptcha.bypass') === true) {
                     if ($this->Users->save($userRegister)) {
                         $user = $this->Auth->identify();
                         if ($user) {
                             $this->Auth->setUser($user);
                         }
                         $user = $this->Users->get($user['id']);
                         //Statistics Event.
                         $this->eventManager()->attach(new Statistics());
                         $stats = new Event('Model.Users.register', $this);
                         $this->eventManager()->dispatch($stats);
                         //Notification Events.
                         $this->eventManager()->attach(new Notifications());
                         $event = new Event('Model.Notifications.new', $this, ['user_id' => $user->id, 'type' => 'bot']);
                         $this->eventManager()->dispatch($event);
                         $viewVars = ['user' => $user, 'name' => $user->full_name];
                         $this->getMailer('User')->send('register', [$user, $viewVars]);
                         $this->Flash->success(__("Your account has been created successfully !"));
                         $url = $this->Auth->redirectUrl();
                         if (substr($this->Auth->redirectUrl(), -5) == 'login') {
                             $url = ['controller' => 'pages', 'action' => 'home'];
//.........这里部分代码省略.........
开发者ID:Xety,项目名称:Xeta,代码行数:101,代码来源:UsersController.php

示例14: _encrypt

 /**
  * Encrypt a value
  *
  * @param type $value Value to be encrypted
  * @return type Encrypted value
  */
 protected function _encrypt($value)
 {
     return Security::encrypt($value, $this->options['key'], $this->options['salt']);
 }
开发者ID:avinashjoshi,项目名称:cakephp-mapstore,代码行数:10,代码来源:MapStoreDB.php


注:本文中的Cake\Utility\Security::encrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。