PHP code example of onepub / revault-api

1. Go to this page and download the library: Download onepub/revault-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onepub / revault-api example snippets




evault\Revault;

$runtime = Revault::load();
// Vault, Lockbox, and AgentSession are now ready to use.



evault\Lockbox;
use Revault\Revault;
use Revault\SecretString;
use Revault\Vault;

$runtime = Revault::load();
$vaultPassphrase = new SecretString($vaultPassphraseFromPrompt);
$vault = Vault::open(
    $runtime->vaultDefaultDirectory(),
    $vaultPassphrase->bytes(),
);
$profileKey = $vault->loadPrivateKey('default');
$lockbox = Lockbox::open('team-secrets.lbox', contact: $profileKey);

try {
    echo $lockbox->description(), PHP_EOL;
    foreach ($lockbox->list('/', true)->entries as $entry) {
        echo $entry->path, PHP_EOL;
    }
} finally {
    $lockbox->close();
    $profileKey->close();
    $vault->close();
    $vaultPassphrase->close();
}

$password = new SecretString($passwordFromPrompt);
$lockbox = Lockbox::open('shared-secrets.lbox', password: $password->bytes());

try {
    echo $lockbox->description(), PHP_EOL;
} finally {
    $lockbox->close();
    $password->close();
}

$length = $lockbox->withSecretVariable(
    'api-token',
    function (FFI\CData $token, int $length): int {
        // Read token[0] through token[$length - 1] only in this callback.
        return $length;
    },
);

$agent = Revault::agentSession();
$agent->start();
$agent->cacheLockboxPassword('team-secrets.lbox', $password->bytes(), 30 * 60);

$lockbox = $agent->openLockboxPassword(
    'team-secrets.lbox',
    $password->bytes(),
);
try {
    // Work with the Lockbox handle held by this process.
} finally {
    $lockbox->close();
    $agent->closeLockbox('team-secrets.lbox');
    $agent->close();
}

$runtime = Revault::load('/opt/my-app/lib/librevault_api.so');