/**
  * Decrypt the value.
  *
  * @return string
  */
 public function decrypted()
 {
     if (!($value = $this->object->getValue())) {
         return null;
     }
     return $this->encrypter->decrypt($value);
 }
 /**
  * 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
 /**
  * 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;
     });
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
Ejemplo n.º 9
0
 /**
  * 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'));
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 12
0
 /**
  * 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 = new \MongoDate($this->getTime() + $minutes * 60);
     $data = array('expiration' => $expiration, 'key' => $key, 'value' => $value);
     $item = $this->getCacheCollection()->where('key', $key)->first();
     if (is_null($item)) {
         $this->getCacheCollection()->insert($data);
     } else {
         $this->getCacheCollection()->where('key', $key)->update($data);
     }
 }
Ejemplo n.º 13
0
 /**
  * Validate a user against the given credentials.
  *
  * @param  \Illuminate\Auth\UserInterface  $user
  * @param  array  $credentials
  * @return bool
  */
 public function validateCredentials(UserInterface $user, array $credentials)
 {
     $plain = $credentials['password'];
     if ($this->encryptedPassword) {
         return $plain == $this->encrypter->decrypt($user->getAuthPassword());
     }
     return $this->hasher->check($plain, $user->getAuthPassword());
 }
 /**
  * Marshal out the pushed job and payload.
  *
  * @throws \Exception
  * @return object
  */
 protected function marshalPushedJob()
 {
     $id = $this->request->header('x-zend-job-id');
     $payload = $this->request->input("payload");
     if (empty($payload)) {
         throw new \Exception("Payload Not Found.");
     }
     $body = $this->crypt->decrypt($payload);
     return (object) ['id' => $id, 'body' => $body, 'pushed' => true];
 }
Ejemplo n.º 15
0
 /**
  * Create a new cookie instance.
  *
  * @param  string  $name
  * @param  string  $value
  * @param  int     $minutes
  * @param  string  $path
  * @param  string  $domain
  * @param  bool    $secure
  * @param  bool    $httpOnly
  * @return \Symfony\Component\HttpFoundation\Cookie
  */
 public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
 {
     list($path, $domain) = $this->getPathAndDomain($path, $domain);
     // Once we calculate the time we can encrypt the message. All cookies will be
     // encrypted using the Illuminate encryption component and will have a MAC
     // assigned to them by the encrypter to make sure they remain authentic.
     $time = $minutes == 0 ? 0 : time() + $minutes * 60;
     $value = $this->encrypter->encrypt($value);
     return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
 }
Ejemplo n.º 16
0
 /**
  * Create a new cookie instance.
  *
  * @param  string  $name
  * @param  string  $value
  * @param  int     $minutes
  * @return Symfony\Component\HttpFoundation\Cookie
  */
 public function make($name, $value, $minutes = 0)
 {
     extract($this->defaults);
     // Once we calculate the time we can encrypt the message. All cookies will be
     // encrypted using the Illuminate encryption component and will have a MAC
     // assigned to them by the encrypter to make sure they remain authentic.
     $time = $minutes == 0 ? 0 : time() + $minutes * 60;
     $value = $this->encrypter->encrypt($value);
     return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
 }
 /**
  * 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.');
     }
 }
Ejemplo n.º 18
0
 /**
  * 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;
 }
 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.');
     }
 }
 /**
  * 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.');
         }
     });
 }
Ejemplo n.º 21
0
 /**
  * @param $secret
  * @return string
  */
 public function retrieve($secret)
 {
     if (!($idKeyArray = explode(';', $secret)) || count($idKeyArray) != 2) {
         throw new \InvalidArgumentException('Invalid secret');
     }
     list($id, $key) = $idKeyArray;
     $id = preg_replace("/[^a-zA-Z\\d]/", '', $id);
     if (!($password = $this->storage->get($id))) {
         throw new PhPsstException('No password with that ID found', PhPsstException::NO_PASSWORD_WITH_ID_FOUND);
     }
     $encrypter = new Encrypter($key, $this->cipher);
     $password->decreaseViews();
     if ($password->getViews() > 0) {
         $this->storage->store($password, true);
     } else {
         $this->storage->delete($password);
     }
     return $encrypter->decrypt($password->getPassword());
 }
Ejemplo n.º 22
0
 /**
  * Decrypt the given value.
  *
  * @param string $payload
  * @return string 
  * @throws \Illuminate\Contracts\Encryption\DecryptException
  * @static 
  */
 public static function decrypt($payload)
 {
     return \Illuminate\Encryption\Encrypter::decrypt($payload);
 }
Ejemplo n.º 23
0
 /**
  * Set the encryption mode.
  *
  * @param string $mode
  * @return void 
  * @static 
  */
 public static function setMode($mode)
 {
     \Illuminate\Encryption\Encrypter::setMode($mode);
 }
Ejemplo n.º 24
0
 /**
  * Create a payload string from the given job and data.
  *
  * @param  string  $job
  * @param  mixed   $data
  * @return string
  */
 protected function createPayload($job, $data = '')
 {
     return $this->crypt->encrypt(parent::createPayload($job, $data));
 }
Ejemplo n.º 25
0
<?php

use Illuminate\Encryption\Encrypter;
require_once 'vendor/autoload.php';
/**
 * Illuminate/encryption
 *
 * Requires: symfony/security-core
 *
 * @source https://github.com/illuminate/encryption
 */
$app = new \Slim\Slim();
$app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
/*
 * This key is used by the Illuminate encrypter service and should be set
 * to a random, 16-character string, otherwise these encrypted strings
 * will not be safe. Please do this before deploying an application!
 */
$key = '1hs8heis)2(-*3d.';
$app->get('/', function () use($key) {
    $encrypter = new Encrypter($key);
    // Encrypt Hello World string
    $encryptedHelloWorld = $encrypter->encrypt('Hello World');
    echo "Here is the encrypted string: <hr>" . $encryptedHelloWorld . "<br><br><br>";
    // Decrypt encrypted string
    $decryptedHelloWorld = $encrypter->decrypt($encryptedHelloWorld);
    echo "Here is the decrypted string: <hr>" . $decryptedHelloWorld . "<br><br>";
});
$app->run();
Ejemplo n.º 26
0
 protected function setupEncryptionKey($force = false)
 {
     $validKey = false;
     $cipher = Config::get('app.cipher');
     $keyLength = $this->getKeyLength($cipher);
     $randomKey = $this->getRandomKey($cipher);
     if ($force) {
         $key = $randomKey;
     } else {
         $this->line(sprintf('Enter a new value of %s characters, or press ENTER to use the generated key', $keyLength));
         while (!$validKey) {
             $key = $this->ask('Application key', $randomKey);
             $validKey = Encrypter::supported($key, $cipher);
             if (!$validKey) {
                 $this->error(sprintf('[ERROR] Invalid key length for "%s" cipher. Supplied key must be %s characters in length.', $cipher, $keyLength));
             }
         }
     }
     $this->writeToConfig('app', ['key' => $key]);
     $this->info(sprintf('Application key [%s] set successfully.', $key));
 }
Ejemplo n.º 27
0
 /**
  * Return the decrypted value of an attribute's encrypted value.
  *
  * @param string    $value
  * @param Encrypter $cipher
  *
  * @return string
  */
 public function decryptedAttribute($value, $cipher)
 {
     return $cipher->decrypt(str_replace($this->getElocryptPrefix(), '', $value));
 }
Ejemplo n.º 28
0
 /**
  *
  * @return Response
  */
 public function etuGuaranteeSubmit()
 {
     $input = Request::only(['guarantee', 'cgv']);
     // Check errors
     $oldGuarantee = EtuUTT::student()->guaranteePayment && in_array(EtuUTT::student()->guaranteePayment->state, ['paid', 'returned', 'refunded']) ? 1 : 0;
     $guarantee = $input['guarantee'] ? 1 : 0;
     if ($input['guarantee'] && $oldGuarantee) {
         return Redirect::back()->withError('Vous ne pouvez pas payer deux fois la caution')->withInput();
     }
     if (!$input['cgv']) {
         return Redirect::back()->withError('Vous devez accepter les conditions générales de vente')->withInput();
     }
     // Calculate amount
     $amount = $guarantee * Config::get('services.wei.guaranteePrice') * 100;
     // Create payment
     $payment = new Payment(['type' => 'guarantee', 'mean' => 'etupay', 'amount' => $amount, 'state' => 'started']);
     $payment->save();
     // Save paiement in user object
     $user = EtuUTT::student();
     if ($guarantee) {
         $user->guarantee_payment = $payment->id;
     }
     $user->save();
     // Calculate EtuPay Payload
     $crypt = new Encrypter(base64_decode(Config::get('services.etupay.key')), 'AES-256-CBC');
     $payload = $crypt->encrypt(json_encode(['type' => 'authorisation', 'amount' => $amount, 'client_mail' => $user->email, 'firstname' => $user->first_name, 'lastname' => $user->last_name, 'description' => 'Formulaire de dépôt de la caution du weekend d\'intégration', 'articles' => [['name' => 'Caution du Week-end d\'intégration', 'price' => Config::get('services.wei.guaranteePrice') * 100, 'quantity' => $guarantee]], 'service_data' => $payment->id]));
     return Redirect(Config::get('services.etupay.uri.initiate') . '?service_id=' . Config::get('services.etupay.id') . '&payload=' . $payload);
 }
Ejemplo n.º 29
0
 /**
  * @param $data
  * @return string
  */
 public function decrypt($data)
 {
     return $this->encrypter->decrypt($data);
 }
Ejemplo n.º 30
0
 /**
  * Get the encryption key.
  *
  * @return string
  * @static
  */
 public static function getKey()
 {
     return \Illuminate\Encryption\Encrypter::getKey();
 }