當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。