Esempio n. 1
0
 /**
  * Decrypt a value
  *
  * ## Usage
  *
  *     $driver->decrypt($string);
  *
  * @param    string           The encrypted value
  * @return   string           The decrypted value
  */
 public function decrypt($string)
 {
     if (!Str::is($string = \base64_decode($string, true))) {
         throw new \Exception('Decryption error. Input value is not valid base64 data.');
     }
     list($iv, $string) = array(Str::sub($string, 0, $this->iv_size()), Str::sub($string, $this->iv_size()));
     return \rtrim(\mcrypt_decrypt(static::$cipher, Crypt::key(), $string, static::$mode, $iv), "");
 }
Esempio n. 2
0
 /**
  * Read all data from a datastore key
  *
  * @param    string           The datastore key
  * @return   string           Returns the contents of the datastore, otherwise null
  */
 public function read($key)
 {
     if (!F::exists(self::$path . $key)) {
         return null;
     }
     // File based caches store have the expiration timestamp stored in
     // UNIX format prepended to their contents. This timestamp is then
     // extracted and removed when the cache is read to determine if the file
     // is still valid
     if (time() >= Str::sub($cache = F::get(self::$path . $key), 0, 10)) {
         $this->delete($key);
         return null;
     }
     return unserialize(substr($cache, 10));
 }