PHP code example of fr3on / php-vault

1. Go to this page and download the library: Download fr3on/php-vault 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/ */

    

fr3on / php-vault example snippets


use Fr3on\Vault\Vault;
use Fr3on\Vault\Kek\LocalKek;

$kek = new LocalKek($masterKeyBytes); // 32 bytes
$vault = new Vault($kek);

$sealed = $vault->seal("Sensitive Transaction Data");
// "v1:AAE... (Base64URL encoded envelope)"

$plaintext = $vault->open($sealed);

use Fr3on\Vault\FieldVault;

$fieldVault = new FieldVault($vault);
$record = [
    'user_id' => 123,
    'email'   => '[email protected]', // sensitive
    'ssn'     => '000-00-0000',      // sensitive
];

$sealed = $fieldVault->sealFields(['email', 'ssn'], $record);
// Only 'email' and 'ssn' are encrypted; 'user_id' remains plaintext.

use Fr3on\Vault\KeyRotator;

$rotator = new KeyRotator();
$newKek = new LocalKek($newMasterKey);

// Rotate the master key without decrypting the payload
$newSealed = $rotator->rotate($oldSealed, $oldKek, $newKek);
bash
composer