本文整理汇总了PHP中Crypto类的典型用法代码示例。如果您正苦于以下问题:PHP Crypto类的具体用法?PHP Crypto怎么用?PHP Crypto使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Crypto类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 <[email protected]>
*/
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
示例16: settings
/**
* Install the application
*/
public function settings()
{
$form = new Form(array('id' => 'install-settings-form', 'labelWidth' => '30em', 'fieldsets' => array('global' => array('legend' => Lang::get('install.settings-global-legend', null, null, $this->language), new TextInput(array('name' => 'title', 'required' => true, 'label' => Lang::get('install.settings-title-label', null, null, $this->language), 'default' => DEFAULT_HTML_TITLE)), new TextInput(array('name' => 'rooturl', 'required' => true, 'label' => Lang::get('install.settings-rooturl-label', null, null, $this->language), 'placeholder' => 'http://', 'default' => getenv('REQUEST_SCHEME') . '://' . getenv('SERVER_NAME'))), new SelectInput(array('name' => 'timezone', 'required' => true, 'options' => array_combine(\DateTimeZone::listIdentifiers(), \DateTimeZone::listIdentifiers()), 'default' => DEFAULT_TIMEZONE, 'label' => Lang::get('install.settings-timezone-label')))), 'database' => array('legend' => Lang::get('install.settings-database-legend', null, null, $this->language), new TextInput(array('name' => 'db[host]', 'required' => true, 'label' => Lang::get('install.settings-db-host-label', null, null, $this->language), 'default' => 'localhost')), new TextInput(array('name' => 'db[username]', 'required' => true, 'label' => Lang::get('install.settings-db-username-label', null, null, $this->language))), new PasswordInput(array('name' => 'db[password]', 'required' => true, 'label' => Lang::get('install.settings-db-password-label', null, null, $this->language), 'pattern' => '/^.*$/')), new TextInput(array('name' => 'db[dbname]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-dbname-label', null, null, $this->language))), new TextInput(array('name' => 'db[prefix]', 'default' => 'Hawk', 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-db-prefix-label', null, null, $this->language)))), 'admin' => array('legend' => Lang::get('install.settings-admin-legend', null, null, $this->language), new TextInput(array('name' => 'admin[login]', 'required' => true, 'pattern' => '/^\\w+$/', 'label' => Lang::get('install.settings-admin-login-label', null, null, $this->language))), new EmailInput(array('name' => 'admin[email]', 'required' => true, 'label' => Lang::get('install.settings-admin-email-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[password]', 'required' => true, 'label' => Lang::get('install.settings-admin-password-label', null, null, $this->language))), new PasswordInput(array('name' => 'admin[passagain]', 'required' => true, 'compare' => 'admin[password]', 'label' => Lang::get('install.settings-admin-passagain-label', null, null, $this->language)))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('install.install-button', null, null, $this->language), 'icon' => 'cog')))), 'onsuccess' => 'location.href = data.rooturl;'));
if (!$form->submitted()) {
// Display the form
$body = View::make(Plugin::current()->getView('settings.tpl'), array('form' => $form));
return \Hawk\Plugins\Main\MainController::getInstance()->index($body);
} else {
// Make the installation
if ($form->check()) {
/**
* Generate Crypto constants
*/
$salt = Crypto::generateKey(24);
$key = Crypto::generateKey(32);
$iv = Crypto::generateKey(16);
$configMode = 'prod';
/**
* Create the database and it tables
*/
$tmpfile = tempnam(sys_get_temp_dir(), '');
DB::add('tmp', array(array('host' => $form->getData('db[host]'), 'username' => $form->getData('db[username]'), 'password' => $form->getData('db[password]'))));
try {
DB::get('tmp');
} catch (DBException $e) {
return $form->response(Form::STATUS_ERROR, Lang::get('install.install-connection-error'));
}
try {
$param = array('{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $language }}' => $this->language, '{{ $timezone }}' => $form->getData('timezone'), '{{ $title }}' => Db::get('tmp')->quote($form->getData('title')), '{{ $email }}' => Db::get('tmp')->quote($form->getData('admin[email]')), '{{ $login }}' => Db::get('tmp')->quote($form->getData('admin[login]')), '{{ $password }}' => Db::get('tmp')->quote(Crypto::saltHash($form->getData('admin[password]'), $salt)), '{{ $ip }}' => Db::get('tmp')->quote(App::request()->clientIp()));
$sql = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/install.sql.tpl'), $param);
// file_put_contents($tmpfile, $sql);
Db::get('tmp')->query($sql);
/**
* Create the config file
*/
$param = array('{{ $salt }}' => addcslashes($salt, "'"), '{{ $key }}' => addcslashes($key, "'"), '{{ $iv }}' => addcslashes($iv, "'"), '{{ $configMode }}' => $configMode, '{{ $rooturl }}' => $form->getData('rooturl'), '{{ $host }}' => $form->getData('db[host]'), '{{ $username }}' => $form->getData('db[username]'), '{{ $password }}' => $form->getData('db[password]'), '{{ $dbname }}' => $form->getData('db[dbname]'), '{{ $prefix }}' => $form->getData('db[prefix]'), '{{ $sessionEngine }}' => $form->getData('session'), '{{ $version }}' => $form->getData('version'));
$config = strtr(file_get_contents(Plugin::current()->getRootDir() . 'templates/config.php.tpl'), $param);
file_put_contents(INCLUDES_DIR . 'config.php', $config);
/**
* Create etc/dev.php
*/
App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-dev.php', ETC_DIR . 'dev.php');
/**
* Create etc/prod.php
*/
App::fs()->copy(Plugin::current()->getRootDir() . 'templates/etc-prod.php', ETC_DIR . 'prod.php');
$form->addReturn('rooturl', $form->getData('rooturl'));
return $form->response(Form::STATUS_SUCCESS, Lang::get('install.install-success'));
} catch (\Exception $e) {
return $form->response(Form::STATUS_ERROR, Lang::get('install.install-error'));
}
}
}
}
开发者ID:elvyrra,项目名称:hawk,代码行数:57,代码来源:InstallController.php
示例17: getToken
function getToken()
{
if (!$this->csrf['token'] || $this->isExpired()) {
$this->csrf['token'] = sha1(session_id() . Crypto::random(16) . SECRET_SALT);
$this->csrf['time'] = time();
} else {
//Reset the timer
$this->csrf['time'] = time();
}
return $this->csrf['token'];
}
开发者ID:dmiguel92,项目名称:osTicket-1.8,代码行数:11,代码来源:class.csrf.php
示例18: testHmacSha1Verify
/**
* Tests Crypto::hmacSha1Verify()
*/
public function testHmacSha1Verify()
{
$string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit';
$key = 'Aliquam erat volutpat';
$expected = '%16%E7%E0E%22%08%5C%2B48%85d%FE%DE%C7%3A%C3%0D%11c';
try {
Crypto::hmacSha1Verify($key, $string, urldecode($expected));
$success = true;
} catch (GeneralSecurityException $e) {
$success = false;
}
$this->assertTrue($success);
}
开发者ID:ahmedadham88,项目名称:enhanced-social-network,代码行数:16,代码来源:CryptoTest.php
示例19: __construct
protected function __construct()
{
$encrypt = \Config::getConfig()->get('encrypt', FALSE);
if ($encrypt) {
$this->crypto = Crypto::getInstance();
}
$config = \Config::factory(\Config::getConfig()->get('cookie', array()), FALSE, 'cookie');
$this->expire = $config->get('expire', 0);
$this->path = $config->get('path', '/');
$this->domain = $config->get('domain', '');
$this->secure = $config->get('secure', FALSE);
$this->httponly = $config->get('httponly', FALSE);
}
开发者ID:hayate,项目名称:unophp,代码行数:13,代码来源:Cookie.php
示例20: verify
/**
* Decrypt then verify a password
*
* @param string $password - The user-provided password
* @param string $stored - The encrypted password hash
* @param EncryptionKey $secret_key - The master key for all passwords
* @return boolean
*/
public static function verify(string $password, string $stored, EncryptionKey $secret_key) : bool
{
// First let's decrypt the hash
$hash_str = Crypto::decrypt($stored, $secret_key);
// Upon successful decryption, verify the password is correct
$isArgon2 = \hash_equals(CryptoUtil::safeSubstr($hash_str, 0, 9), \Sodium\CRYPTO_PWHASH_STRPREFIX);
$isScrypt = \hash_equals(CryptoUtil::safeSubstr($hash_str, 0, 3), \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_STRPREFIX);
if ($isArgon2) {
return \Sodium\crypto_pwhash_str_verify($hash_str, $password);
} elseif ($isScrypt) {
return \Sodium\crypto_pwhash_scryptsalsa208sha256_str_verify($hash_str, $password);
}
return false;
}
开发者ID:AndrewCarterUK,项目名称:halite,代码行数:22,代码来源:Password.php
注:本文中的Crypto类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论