. */ namespace SP\Core\Crypt; /** * Class Vault * * @package SP\Core\Crypt */ class Vault { /** * @var string */ private $data; /** * @var string */ private $key; /** * @var int */ private $timeSet = 0; /** * @var int */ private $timeUpdated = 0; /** * Regenerar la clave de sesión * * @param string $newSeed * @param string $oldSeed * @return Vault * @throws \Defuse\Crypto\Exception\CryptoException */ public function reKey($newSeed, $oldSeed) { $this->timeUpdated = time(); $sessionMPass = $this->getData($oldSeed); $this->saveData($sessionMPass, $newSeed); return $this; } /** * Devolver la clave maestra de la sesión * * @param string $key * @return string * @throws \Defuse\Crypto\Exception\CryptoException */ public function getData($key) { return Crypt::decrypt($this->data, Crypt::unlockSecuredKey($this->key, $key), $key); } /** * Guardar la clave maestra en la sesión * * @param mixed $data * @param string $key * @return $this * @throws \Defuse\Crypto\Exception\CryptoException */ public function saveData($data, $key) { if ($this->timeSet === 0) { $this->timeSet = time(); } $this->key = Crypt::makeSecuredKey($key); $this->data = Crypt::encrypt($data, $this->key, $key); return $this; } /** * @return int */ public function getTimeSet() { return $this->timeSet; } /** * @return int */ public function getTimeUpdated() { return $this->timeUpdated; } }