/** * Runs the cli * * @return int */ public function run() { $countChanged = 0; $from = $this->getArg('f', 'from', null, true); $to = $this->getArg('t', 'to', null, true); $cipher = $this->getArg('c', 'cipher', $this->crypto->getCipher()); $this->crypto->setCipher($cipher); $this->printLine("Using the cipher: {$cipher}"); $this->printLine("Changing the key {$from} to {$to}"); $container = new Container(); $containerList = $container->readList(); foreach ($containerList as $container) { /** @var Container $container */ $data = $this->crypto->decrypt($container->getContainer(), $from); if ($data === false) { continue; } $container->setContainer($this->crypto->encrypt($data, $to)); $container->save(); $container->clear(); $countChanged++; } $this->printLine("Changed {$countChanged} passwords"); }
/** * DELETE /password/:key/:id * * @param string $key * @param int $id */ public function delete($key, $id) { $container = new Container(); if ($container->read($id) && $this->crypto->decrypt($container->getContainer(), $key) !== false) { $this->app->render($container->delete() ? 200 : 500, ['response' => $id]); } else { $this->app->render(404); } }