Filebase icon indicating copy to clipboard operation
Filebase copied to clipboard

Added Encryption to the project and updated the readme

Open mitmelon opened this issue 1 year ago • 0 comments

(11) Encryption Added

  • 🌟 Added Encryption mechanism to the document. You can now encrypt and decrypt all your documents by passing an encryption array to the config settings as shown below;
require_once __DIR__."/vendor/autoload.php";

/**
 * @settings array $encryption
 * @param key_storage_path - The path to where your encryption keys are stored
 * @key_name - The name of your key which points to the name of the key file (Store this name in your database)
 */

$db = new \Filebase\Database([
    'dir' => __DIR__.'/databases',
    'encryption' => array('key_storage_path' => __DIR__.'/encrypter',  'key_name' => 'test')
]);

$db->flush(true);
$user = $db->get(uniqid());
$user->name  = 'John';
$user->email = '[email protected]';
$user->save();
$db->where('name','=','John')->andWhere('email','==','[email protected]')->select('email')->results();
$result_from_cache = $db->where('name','=','John')->andWhere('email','==','[email protected]')->select('email')->results();
print_r($result_from_cache);

The above will encrypt your document when creating and decrypt it when fetching or quering. Please note that its required that you have the extension Sodium installed to use the encryption mechanism.

mitmelon avatar Jan 25 '23 18:01 mitmelon