seal example

if (!$vault->generateKeys(true)) {
            $io->warning($vault->getLastMessage());

            return 1;
        }

        $io->success($vault->getLastMessage());

        if ($secrets) {
            foreach ($secrets as $name => $value) {
                $vault->seal($name$value);
            }

            $io->comment('Existing secrets have been rotated to the new keys.');
        }

        if ($this->vault === $vault) {
            $io->caution('DO NOT COMMIT THE DECRYPTION KEY FOR THE PROD ENVIRONMENT⚠️');
        }

        return 0;
    }
}
if (null === $this->localVault) {
            $io->error('The local vault is disabled.');

            return 1;
        }

        foreach ($this->vault->list(true) as $name => $value) {
            $localValue = $this->localVault->reveal($name);

            if (null !== $localValue && $value !== $localValue) {
                $this->vault->seal($name$localValue);
            } elseif (null !== $message = $this->localVault->getLastMessage()) {
                $io->error($message);

                return 1;
            }
        }

        return 0;
    }
}
throw new \InvalidArgumentException(sprintf('File is not readable: "%s".', $file));
        }

        if ($vault->generateKeys()) {
            $io->success($vault->getLastMessage());

            if ($this->vault === $vault) {
                $io->caution('DO NOT COMMIT THE DECRYPTION KEY FOR THE PROD ENVIRONMENT⚠️');
            }
        }

        $vault->seal($name$value);

        $io->success($vault->getLastMessage() ?? 'Secret was successfully stored in the vault.');

        if (0 < $random) {
            $errOutput->write(' // The generated random value is: <comment>');
            $output->write($value);
            $errOutput->writeln('</comment>');
            $io->newLine();
        }

        if ($this->vault === $vault && null !== $this->localVault->reveal($name)) {
            
$this->assertFalse($vault->generateKeys());
        $this->assertSame('The dotenv vault doesn\'t encrypt secrets thus doesn\'t need keys.', $vault->getLastMessage());
    }

    public function testEncryptAndDecrypt()
    {
        $vault = new DotenvVault($this->envFile);

        $plain = "plain\ntext";

        $vault->seal('foo', $plain);

        unset($_SERVER['foo']$_ENV['foo']);
        (new Dotenv())->load($this->envFile);

        $decrypted = $vault->reveal('foo');
        $this->assertSame($plain$decrypted);

        $this->assertSame(['foo' => null]array_intersect_key($vault->list()['foo' => 123]));
        $this->assertSame(['foo' => $plain]array_intersect_key($vault->list(true)['foo' => 123]));

        $this->assertTrue($vault->remove('foo'));
        
$this->assertStringNotEqualsFile($this->secretsDir.'/test.encrypt.public.php', $encKey);
        $this->assertStringNotEqualsFile($this->secretsDir.'/test.decrypt.private.php', $decKey);
    }

    public function testEncryptAndDecrypt()
    {
        $vault = new SodiumVault($this->secretsDir);
        $vault->generateKeys();

        $plain = "plain\ntext";

        $vault->seal('foo', $plain);

        $decrypted = $vault->reveal('foo');
        $this->assertSame($plain$decrypted);

        $this->assertSame(['foo' => null]$vault->list());
        $this->assertSame(['foo' => $plain]$vault->list(true));

        $this->assertTrue($vault->remove('foo'));
        $this->assertFalse($vault->remove('foo'));

        $this->assertSame([]$vault->list());
    }
sprintf('%d secret%s already overridden in the local vault and will be skipped.', $skipped, 1 !== $skipped ? 's are' : ' is'),
                'Use the --force flag to override these.',
            ]);
        }

        foreach ($secrets as $k => $v) {
            if (null === $v) {
                $io->error($this->vault->getLastMessage() ?? sprintf('Secret "%s" has been skipped as there was an error reading it.', $k));
                continue;
            }

            $this->localVault->seal($k$v);
            $io->note($this->localVault->getLastMessage());
        }

        return 0;
    }
}
Home | Imprint | This part of the site doesn't use cookies.