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


PHP Crypto类代码示例

本文整理汇总了PHP中Crypto的典型用法代码示例。如果您正苦于以下问题:PHP Crypto类的具体用法?PHP Crypto怎么用?PHP Crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addUser

function addUser($mysqli, $email, $pwd)
{
    $crypto = new Crypto();
    $salt = $crypto->generateSalt(10);
    $hash = $crypto->generateHash($pwd, $salt);
    $sql = "INSERT INTO users(email, hash, salt, nbrAttempts) \n\t\t\tVALUES('" . $email . "', '" . $hash . "', '" . $salt . "', '0')";
    $mysqli->multi_query($sql);
    $_SESSION['isLoggedIn'] = 1;
    $_SESSION['username'] = $email;
    redirect("https://127.0.0.1/searchView.php");
}
开发者ID:HampusBalldin,项目名称:EITF05,代码行数:11,代码来源:register.php

示例2: hmacSha1Verify

 public static function hmacSha1Verify($key, $in, $expected)
 {
     $hmac = Crypto::hmacSha1($key, $in);
     if ($hmac != $expected) {
         throw new GeneralSecurityException("HMAC verification failure");
     }
 }
开发者ID:dalinhuang,项目名称:shopexts,代码行数:7,代码来源:Crypto.php

示例3: unwrap

 /**
  * {@inheritDoc}
  */
 public function unwrap($in, $maxAgeSec)
 {
     //TODO remove this once we have a better way to generate a fake token
     // in the example files
     if (Config::get('allow_plaintext_token') && count(explode(':', $in)) == 6) {
         $data = explode(":", $in);
         $out = array();
         $out['o'] = $data[0];
         $out['v'] = $data[1];
         $out['a'] = $data[2];
         $out['d'] = $data[3];
         $out['u'] = $data[4];
         $out['m'] = $data[5];
     } else {
         //TODO Exception handling like JAVA
         $bin = base64_decode($in);
         $cipherText = substr($bin, 0, strlen($bin) - Crypto::$HMAC_SHA1_LEN);
         $hmac = substr($bin, strlen($cipherText));
         Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac);
         $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText);
         $out = $this->deserialize($plain);
         $this->checkTimestamp($out, $maxAgeSec);
     }
     return $out;
 }
开发者ID:jkinner,项目名称:ringside,代码行数:28,代码来源:BasicBlobCrypter.php

示例4: unwrap

 /**
  * @see BasicBlobCrypter::unwrap();
  */
 public function unwrap($in, $maxAgeSec)
 {
     if ($this->allowPlaintextToken && count(explode(':', $in)) == 7) {
         $data = explode(":", $in);
         $out = array();
         $out['o'] = $data[0];
         $out['v'] = $data[1];
         $out['a'] = $data[2];
         $out['d'] = $data[3];
         $out['u'] = $data[4];
         $out['m'] = $data[5];
     } else {
         $bin = base64_decode($in);
         if (is_callable('mb_substr')) {
             $cipherText = mb_substr($bin, 0, -Crypto::$HMAC_SHA1_LEN, 'latin1');
             $hmac = mb_substr($bin, mb_strlen($cipherText, 'latin1'), Crypto::$HMAC_SHA1_LEN, 'latin1');
         } else {
             $cipherText = substr($bin, 0, -Crypto::$HMAC_SHA1_LEN);
             $hmac = substr($bin, strlen($cipherText));
         }
         Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac);
         $plain = base64_decode($cipherText);
         if ($this->allowPlaintextToken) {
             $plain = base64_decode($cipherText);
         } else {
             $plain = opShindigCrypto::decrypt($this->cipherKey, $cipherText);
         }
         $out = $this->deserialize($plain);
         $this->checkTimestamp($out, $maxAgeSec);
     }
     return $out;
 }
开发者ID:niryuu,项目名称:opOpenSocialPlugin,代码行数:35,代码来源:opShindigBlobCrypter.class.php

示例5: ConvertPaymentModules

 public function ConvertPaymentModules()
 {
     $this->Log('Convert payment modules');
     // Clear tables
     $this->TruncateTable('pmodules', 'pmodules_config');
     // Copy pmodules table
     $pmodule_rset = $this->DbOld->GetAll('SELECT * FROM pmodules');
     foreach ($pmodule_rset as &$row) {
         if ($row['name'] == 'offline_payment') {
             $row['name'] = 'OfflineBank';
         }
     }
     $this->BulkInsert('pmodules', $pmodule_rset);
     // For each pmodule copy config settings
     $pmodule_config = array();
     $Crypto = $GLOBALS['Crypto'];
     foreach ($pmodule_rset as $pmodule) {
         // Get old config form for current pmodule
         $rset = $this->DbOld->GetAll('SELECT * FROM pmodules_config WHERE module_name = ?', array($pmodule['name']));
         foreach ($rset as $row) {
             // Encrypt config value
             $row['value'] = $this->Crypto->Encrypt($row['key'], LICENSE_FLAGS::REGISTERED_TO);
             // Push it to pmodule config
             $pmodule_config[] = $row;
         }
     }
     $this->BulkInsert('pmodules_config', $pmodule_config);
 }
开发者ID:rchicoria,项目名称:epp-drs,代码行数:28,代码来源:upgrade-to-v31-lu.php

示例6: decrypt

 public static function decrypt($string, $key = null, $salt = null, $iv = null)
 {
     $config = ConfigManager::getConfig('Crypto', 'AES256')->AuxConfig;
     if ($key === null) {
         $key = $config->key;
     }
     if ($salt === null) {
         $salt = $config->salt;
     }
     if ($iv === null) {
         $iv = $config->iv;
     }
     $td = mcrypt_module_open('rijndael-128', '', MCRYPT_MODE_CBC, '');
     $ks = mcrypt_enc_get_key_size($td);
     $bs = mcrypt_enc_get_block_size($td);
     $iv = substr(hash("sha256", $iv), 0, $bs);
     // Create key
     $key = Crypto::pbkdf2("sha512", $key, $salt, $config->pbkdfRounds, $ks);
     // Initialize encryption module for decryption
     mcrypt_generic_init($td, $key, $iv);
     $decryptedString = "";
     // Decrypt encrypted string
     try {
         if (ctype_xdigit($string)) {
             $decryptedString = trim(mdecrypt_generic($td, pack("H*", $string)));
         }
     } catch (ErrorException $e) {
     }
     // Terminate decryption handle and close module
     mcrypt_generic_deinit($td);
     mcrypt_module_close($td);
     // Show string
     return $decryptedString;
 }
开发者ID:Welvin,项目名称:stingle,代码行数:34,代码来源:AES256.class.php

示例7: isAuthenticated

 public function isAuthenticated($request)
 {
     $currentTime = time();
     if (isset($request[$this->cookieName])) {
         $connection = $request[$this->cookieName]['CON'];
         $timestamp = $request[$this->cookieName]['TM'];
         if ($connection && $timestamp) {
             if ($currentTime - $timestamp < $this->cookieExpireTime) {
                 $temp = Crypto::decrypt($connection, _Key_New);
                 list($username) = explode("|Z|1|Z|", $temp);
                 if ($username) {
                     $connection = Crypto::encrypt(implode("|Z|1|Z|", array($username, time())), _Key_New);
                     $this->setAuthenticated($connection);
                     return true;
                 }
             } else {
                 // Timed-out
                 return false;
             }
         } else {
             // Not Authenticated
             return false;
         }
     }
 }
开发者ID:naukri-engineering,项目名称:NewMonk,代码行数:25,代码来源:AuthenticationManager.php

示例8: testRandom

 function testRandom()
 {
     for ($i = 1; $i < 128; $i += 4) {
         $data = Crypto::random($i);
         $this->assertNotEqual($data, '', 'Empty random data generated');
         $this->assert(strlen($data) == $i, 'Random data received was not the length requested');
     }
 }
开发者ID:pkdevboxy,项目名称:osTicket-1.7,代码行数:8,代码来源:test.crypto.php

示例9: writeLog

 public function writeLog($message, $mode = 'all')
 {
     $time = date("F j, Y, g:i a");
     $ip = $_SERVER['REMOTE_ADDR'];
     $message = basename($_SERVER['SCRIPT_FILENAME']) . " [{$ip}] ({$time}) : " . $message;
     $msg = base64_encode(base64_encode(Crypto::EncryptString(base64_decode(base64_decode(ADMIN_KEY)), base64_decode(base64_decode(ADMIN_IV)), $message)));
     DbManager::i()->insert("sf_logs", array("message", "mode"), array($msg, $mode));
 }
开发者ID:sharedRoutine,项目名称:ShopFix,代码行数:8,代码来源:class.logger.php

示例10: createWalletUser

 public function createWalletUser($username, $password, $email, $token)
 {
     $walletClient = new Client(null, null, $this->walletApiUrl);
     $keys = $this->getUserKeys($username, $password, array('wallet', 'api', 'key'));
     $account = array('token' => $token, 'username' => $username, 'email' => $email, 'country' => '', 'timezone' => '', 'keys' => array('wallet' => $keys['wallet']['private'], 'api' => Crypto::signData($keys['api']['private']), 'key' => Crypto::signData($keys['key']['private'])));
     $result = $walletClient->query('user/create', 'POST', $account, false);
     return $result;
 }
开发者ID:holytransaction,项目名称:ht-client-php,代码行数:8,代码来源:HolyTransaction.php

示例11: setSchema

 /**
  * Configura o schema do model corrente
  *
  * @return 	void
  */
 public function setSchema()
 {
     $esquema = Cache::read('Esquema.' . $this->name);
     if (!isset($esquema) || empty($esquema)) {
         $meuEsquema = isset($this->esquema) ? $this->esquema : array();
         $this->esquema = array();
         $this->schema();
         foreach ($this->_schema as $_field => $_arrProp) {
             $this->esquema[$_field] = isset($meuEsquema[$_field]) ? $meuEsquema[$_field] : array();
             $this->esquema[$_field]['alias'] = isset($meuEsquema[$_field]['alias']) ? $meuEsquema[$_field]['alias'] : Crypto::word($_field);
             $this->esquema[$_field]['type'] = isset($meuEsquema[$_field]['type']) ? $meuEsquema[$_field]['type'] : $_arrProp['type'];
             if (isset($_arrProp['key'])) {
                 $this->esquema[$_field]['key'] = $_arrProp['key'];
             }
             if (isset($_arrProp['key'])) {
                 $this->esquema[$_field]['sort'] = true;
             }
             $input = isset($meuEsquema[$_field]['input']) ? $meuEsquema[$_field]['input'] : array();
             $input['label'] = isset($meuEsquema[$_field]['input']['label']) ? $meuEsquema[$_field]['input']['label'] : ucfirst(Inflector::camelize($_field));
             $input['type'] = isset($meuEsquema[$_field]['input']['type']) ? $meuEsquema[$_field]['input']['type'] : 'text';
             $input['div'] = isset($meuEsquema[$_field]['input']['div']) ? $meuEsquema[$_field]['input']['div'] : 'div' . Crypto::word(Inflector::camelize($this->name . '_' . $_field)) . ' div' . Crypto::word(Inflector::camelize($_field));
             if (isset($_arrProp['default'])) {
                 $input['default'] = $_arrProp['default'];
             }
             if (isset($_arrProp['null']) && $_arrProp['null'] === false) {
                 $input['required'] = 'required';
             }
             if (isset($_arrProp['length'])) {
                 $input['maxlength'] = $_arrProp['length'];
             }
             if (in_array($_field, array('criado', 'modificado'))) {
                 unset($input['required']);
                 $input['disabled'] = 'disabled';
             }
             if (in_array($_arrProp['type'], array('date', 'data', 'datetime')) && !isset($input['disabled'])) {
                 $input['class'] = isset($input['class']) ? $input['class'] : ' in-data';
             }
             if (in_array($_arrProp['type'], array('text'))) {
                 $input['type'] = 'textarea';
             }
             if (in_array($_arrProp['type'], array('decimal'))) {
                 $length = isset($_arrProp['length']) ? $_arrProp['length'] : null;
                 if (isset($length)) {
                     $input['maxlength'] = round($input['maxlength']) + round($input['maxlength']) / 3 - 1;
                     $length = substr($length, strpos($length, ',') + 1, strlen($length));
                     $this->esquema[$_field]['decimais'] = $length;
                 }
                 $input['class'] = isset($input['class']) ? $input['class'] : ' in-decimal';
             }
             $this->esquema[$_field]['input'] = $input;
         }
         if (USAR_CACHE === true) {
             Cache::write('Esquema.' . $this->name, $this->esquema);
         }
     } else {
         $this->esquema = $esquema;
     }
 }
开发者ID:adrianodemoura,项目名称:cakeGrid,代码行数:63,代码来源:XGridAppModel.php

示例12: setUpBeforeClass

 /**
  * This method is called before the first test of this test class is run.
  *
  * @return  void
  */
 public static function setUpBeforeClass()
 {
     // Only run the test if the environment supports it.
     try {
         Crypto::RuntimeTest();
     } catch (CryptoTestFailedException $e) {
         self::markTestSkipped('The environment cannot safely perform encryption with this cipher.');
     }
 }
开发者ID:SysBind,项目名称:joomla-cms,代码行数:14,代码来源:JCryptCipherCryptoTest.php

示例13: getSecurePOSTRedirectURL

 /**
  * Obtain a URL where we can redirect to securely post a form with the given data to a specific destination.
  *
  * @param string $destination The destination URL.
  * @param array  $data An associative array containing the data to be posted to $destination.
  *
  * @return string  A URL which allows to securely post a form to $destination.
  *
  * @author Jaime Perez, UNINETT AS <jaime.perez@uninett.no>
  */
 private static function getSecurePOSTRedirectURL($destination, $data)
 {
     $session = \SimpleSAML_Session::getSessionFromRequest();
     $id = self::savePOSTData($session, $destination, $data);
     // encrypt the session ID and the random ID
     $info = base64_encode(Crypto::aesEncrypt($session->getSessionId() . ':' . $id));
     $url = \SimpleSAML_Module::getModuleURL('core/postredirect.php', array('RedirInfo' => $info));
     return preg_replace('#^https:#', 'http:', $url);
 }
开发者ID:mrvanes,项目名称:simplesamlphp,代码行数:19,代码来源:HTTP.php

示例14: decrypt

 public static function decrypt($key, $text)
 {
     if (extension_loaded('mcrypt')) {
         return Crypto::aes128cbcDecrypt($key, $text);
     }
     $iv = substr($text, 0, 8);
     $encrypted = substr($text, 8, strlen($text));
     $blowfish = Crypt_Blowfish::factory('cbc', $key, $iv);
     return base64_decode($blowfish->decrypt($encrypted));
 }
开发者ID:niryuu,项目名称:opOpenSocialPlugin,代码行数:10,代码来源:opShindigCrypto.class.php

示例15: isLoggedIn

 /**
  * Check if a user is logged in
  */
 public static function isLoggedIn()
 {
     if (empty($_COOKIE['s'])) {
         return false;
     } else {
         $str = Crypto::decrypt($_COOKIE['s'], $_SERVER['ENCRYPTION_KEY']);
         $fields = explode(':', $str);
         return $fields[1];
         // return the userid
     }
 }
开发者ID:excitom,项目名称:megan-mvc,代码行数:14,代码来源:Cookies.php


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