/** * 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"); }
/** * PUT /password/:key/:id * * @param string $key * @param int $id */ public function edit($key, $id) { $container = new Container(); if ($container->read($id)) { $rawData = $this->app->request()->getBody(); $container->setContainer($this->crypto->encrypt($rawData, $key)); $this->app->render($container->save() ? 200 : 500, ['response' => $id]); } else { $this->app->render(404); } }