file-vault icon indicating copy to clipboard operation
file-vault copied to clipboard

Tips: encrypting local to remote(S3)

Open mikkame opened this issue 3 years ago • 1 comments

$crypt = new FileEncrypter(config('file-vault.key'), config('file-vault.cipher'));
$crypt->encrypt('local-path', 's3://bucket-name/path');

It working in my case.

mikkame avatar Feb 01 '21 10:02 mikkame

Additional tips if you're using multi-tenancy and don't want to use the Storage facade, This will take the file upload (/tmp/12345) and encrypt the contents into a temporary file for the request (/tmp/abcdef), then upload it afterwards.

use SoareCostin\FileVault\FileEncrypter;
use Illuminate\Support\Str;
use \Storage;

    $save_as = (string)Str::uuid() . '.' . strtolower($this->request->file('blob')->getClientOriginalExtension()); // my_photo.JPEG

    $temporary = tmpfile();

    $encrypter = new FileEncrypter (config('file-vault.key'), config('file-vault.cipher'));
    $encrypter->encrypt ($this->request->file('blob')->path(), stream_get_meta_data($temporary)['uri']);

    Storage::disk ($this->disk)->put ($this->folder_prefix.'/'.$save_as, stream_get_meta_data($temporary)['uri']);

alexc-wormhole avatar Oct 22 '21 01:10 alexc-wormhole