本文整理汇总了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");
}
示例2: hmacSha1Verify
public static function hmacSha1Verify($key, $in, $expected)
{
$hmac = Crypto::hmacSha1($key, $in);
if ($hmac != $expected) {
throw new GeneralSecurityException("HMAC verification failure");
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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');
}
}
示例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));
}
示例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;
}
示例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;
}
}
示例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.');
}
}
示例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);
}
示例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));
}
示例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
}
}