本文整理汇总了PHP中Illuminate\Encryption\Encrypter类的典型用法代码示例。如果您正苦于以下问题:PHP Encrypter类的具体用法?PHP Encrypter怎么用?PHP Encrypter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Encrypter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readCallback
public static function readCallback($payload)
{
$crypt = new Encrypter(base64_decode(Config::get('services.etupay.key')), 'AES-256-CBC');
$payload = json_decode($crypt->decrypt($payload));
if ($payload && is_numeric($payload->service_data)) {
$paymentId = $payload->service_data;
$payment = Payment::findOrFail($paymentId);
switch ($payload->step) {
case 'INITIALISED':
$payment->state = 'returned';
break;
case 'PAID':
case 'AUTHORISATION':
$payment->state = 'paid';
break;
case 'REFUSED':
case 'CANCELED':
$payment->state = 'refused';
break;
case 'REFUNDED':
$payment->state = 'refunded';
break;
}
$payment->informations = ['transaction_id' => $payload->transaction_id];
$payment->save();
if ($payment->newcomer) {
$payment->newcomer->updateWei();
} elseif ($payment->student) {
$payment->student->updateWei();
}
return $payment;
}
return null;
}
示例2: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('encrypter', function ($app) {
$encrypter = new Encrypter($app['config']['app.key']);
if ($app['config']->has('app.cipher')) {
$encrypter->setCipher($app['config']['app.cipher']);
}
return $encrypter;
});
}
示例3: decrypt
/**
* Descriptografa os dados.
*
* @param array $data
* @return array
*/
public function decrypt(array $data)
{
if (!isset($data['secret'])) {
return $data;
}
$key = md5($data['secret'] . '-' . Config::get('app.key'));
$cipher = Config::get('app.cipher');
$encrypter = new Encrypter($key, $cipher);
foreach ($data as $key => $value) {
if (!empty($value) and in_array($key, $this->getEncryptable())) {
$data[$key] = $encrypter->decrypt($value);
}
}
return $data;
}
示例4: getEncrypterForKeyAndCipher
/**
* Get the proper encrypter instance for the given key and cipher.
*
* @param string $key
* @param string $cipher
* @return mixed
*
* @throws \RuntimeException
*/
protected function getEncrypterForKeyAndCipher($key, $cipher)
{
if (Encrypter::supported($key, $cipher)) {
return new Encrypter($key, $cipher);
} elseif (McryptEncrypter::supported($key, $cipher)) {
return new McryptEncrypter($key, $cipher);
} else {
throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
}
}
示例5: handle
/**
* executes the command
*/
protected function handle()
{
$config = $this->getApplication()->config();
if (!$config->has('url') || !$this->confirm('Is your donePM API url ' . $config->get('url') . '?', true)) {
$url = $this->ask('What is your donePM API url?', Application::API_URL);
$config->set('url', $url);
}
if (!$config->has('email') || !$this->confirm('Is your donePM email ' . $config->get('email') . '?', true)) {
$email = $this->ask('What is your donePM email?');
$config->set('email', $email);
}
if (!$config->has('password') || !$this->confirm('Do you want to keep your password?', true)) {
$password = $this->secret('What is your donePM password? (will be stored encrypted)');
$key = $config->get('key', Str::random(16));
$encrypter = new Encrypter($key);
$config->set('password', $encrypter->encrypt($password));
$config->set('key', $key);
}
$this->getApplication()->writeConfig($config);
return 0;
}
示例6: getEncrypter
private static function getEncrypter()
{
$config = static::getEncrypterVariables();
$key = $config['key'];
$cipher = $config['cipher'];
if (Encrypter::supported($key, $cipher)) {
return new Encrypter($key, $cipher);
} elseif (McryptEncrypter::supported($key, $cipher)) {
return new McryptEncrypter($key, $cipher);
} else {
throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
}
}
示例7: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('encrypter', function ($app) {
$config = $app->make('config')->get('app');
$key = $config['key'];
$cipher = $config['cipher'];
if (Encrypter::supported($key, $cipher)) {
return new Encrypter($key, $cipher);
} elseif (McryptEncrypter::supported($key, $cipher)) {
return new McryptEncrypter($key, $cipher);
} else {
throw new RuntimeException('No supported encrypter found. The cipher and / or key length are invalid.');
}
});
}
示例8: decrypted
/**
* Decrypt the value.
*
* @return string
*/
public function decrypted()
{
if (!($value = $this->object->getValue())) {
return null;
}
return $this->encrypter->decrypt($value);
}
示例9: restore
/**
* Restore the value.
*
* @param $value
* @return string
*/
public function restore($value)
{
if (array_get($this->fieldType->getConfig(), 'auto_decrypt') === true) {
return $this->encrypter->decrypt($value);
}
return $value;
}
示例10: encrypt
/**
* Encrypt the cookies on an outgoing response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function encrypt(Response $response)
{
foreach ($response->headers->getCookies() as $key => $c) {
$encrypted = $this->encrypter->encrypt($c->getValue());
$response->headers->setCookie($this->duplicate($c, $encrypted));
}
return $response;
}
示例11: decrypted
/**
* Decrypt the value.
*
* @return string
*/
public function decrypted()
{
if (!($value = $this->object->getValue())) {
return null;
}
// Return the value if it's already decoded.
if (array_get($this->object->getConfig(), 'auto_decrypt') === true) {
return $value;
}
return $this->encrypter->decrypt($value);
}
示例12: put
/**
* Store an item in the cache for a given number of minutes.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes)
{
// All of the cached values in the database are encrypted in case this is used
// as a session data store by the consumer. We'll also calculate the expire
// time and place that on the table so we will check it on our retrieval.
$value = $this->encrypter->encrypt($value);
$timestamp = $this->getTime();
$expiration = $ttl = $timestamp + $minutes * 60;
// Remove key/value store if exists
$this->forget($key);
$this->columnFamily->insert($this->prefix . $key, compact('value', 'expiration'), $timestamp, $ttl);
}
示例13: deserializeToken
/**
* Deserializes token.
*
* @param string $payload
* @return AuthToken|null
*/
public function deserializeToken($payload)
{
try {
$data = $this->encrypter->decrypt($payload);
} catch (DecryptException $e) {
return null;
}
if (empty($data['id']) || empty($data['key'])) {
return null;
}
$token = $this->generateAuthToken($data['key']);
$token->setAuthIdentifier($data['id']);
return $token;
}
示例14: put
/**
* Store an item in the cache for a given number of minutes.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes)
{
$key = $this->prefix . $key;
// All of the cached values in the database are encrypted in case this is used
// as a session data store by the consumer. We'll also calculate the expire
// time and place that on the table so we will check it on our retrieval.
$value = $this->encrypter->encrypt($value);
$expiration = $this->getTime() + $minutes * 60;
try {
$this->table()->insert(compact('key', 'value', 'expiration'));
} catch (\Exception $e) {
$this->table()->where('key', '=', $key)->update(compact('value', 'expiration'));
}
}
示例15: deserializeToken
/**
* Deserializes token.
*
* @param string $payload
* @return AuthToken|null
*/
public function deserializeToken($payload)
{
try {
$payload = str_replace(array('-', '_'), array('+', '/'), $payload);
$data = $this->encrypter->decrypt($payload);
} catch (DecryptException $e) {
return null;
}
if (empty($data['id']) || empty($data['key']) || empty($data['userAgent'])) {
return null;
}
$token = $this->generateAuthToken($data['key']);
$token->setAuthIdentifier($data['id']);
$token->setUserAgent($data['userAgent']);
return $token;
}