PHPackages                             alejandro-ap00/file-vault - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. alejandro-ap00/file-vault

ActiveLibrary[File &amp; Storage](/categories/file-storage)

alejandro-ap00/file-vault
=========================

A Laravel package for encrypting and decrypting files of any size

v1.0.0(2y ago)142[4 PRs](https://github.com/Alejandro-AP00/file-vault/pulls)MITPHPPHP ^8.2CI passing

Since May 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/Alejandro-AP00/file-vault)[ Packagist](https://packagist.org/packages/alejandro-ap00/file-vault)[ Docs](https://github.com/alejandro-ap00/file-vault)[ GitHub Sponsors]()[ RSS](/packages/alejandro-ap00-file-vault/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (6)Used By (0)

A Laravel package for encrypting and decrypting files of any size
=================================================================

[](#a-laravel-package-for-encrypting-and-decrypting-files-of-any-size)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e6e4e260345dbbb5f80b74f87dbcf23f88b1ef932142adeba42675a84e1dbd38/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c656a616e64726f2d617030302f66696c652d7661756c742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alejandro-ap00/file-vault)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8b8a2f98558ef10ecdcc2c64b4a5ae8f8de173fa8363f2d9bb1122f185b72b41/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c656a616e64726f2d617030302f66696c652d7661756c742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/alejandro-ap00/file-vault/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/c0d552792000d3c3a26fa9f04945c03159a9ee0c20f0e9f5e11d7def087cf934/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c656a616e64726f2d617030302f66696c652d7661756c742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/alejandro-ap00/file-vault/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3176b6d75584c8e95b4cfdc75f6cc13741bac067ddc552ad2c164730b198ddde/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c656a616e64726f2d617030302f66696c652d7661756c742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alejandro-ap00/file-vault)

With this package, you can encrypt and decrypt files of any size in your Laravel project. This package uses streams and [CBC encryption](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_(CBC)), encrypting / decrypting a segment of data at a time.

Fork
----

[](#fork)

This package is forked from [soarecostin/file-vault](https://github.com/soarecostin/file-vault) to add Laravel 10 and 11 support.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require alejandro-ap00/file-vault
```

You can publish the config file with:

```
php artisan vendor:publish --tag="file-vault-config"
```

This is the contents of the published config file:

```
return [
    /*
     * The default key used for all file encryption / decryption
     * This package will look for a FILE_VAULT_KEY in your env file
     * If no FILE_VAULT_KEY is found, then it will use your Laravel APP_KEY
     */
    'key' => env('FILE_VAULT_KEY', env('APP_KEY')),

    /*
     * The cipher used for encryption.
     * Supported options are AES-128-CBC and AES-256-CBC
     */
    'cipher' => 'AES-256-CBC',

    /*
     * The Storage disk used by default to locate your files.
     */
    'disk' => 'local',
];
```

Usage
-----

[](#usage)

### Tutorials

[](#tutorials)

For a detailed description of how to encrypt files in Laravel using this package, please see the following articles:

- [Part 1: How to encrypt large files in Laravel](https://medium.com/swlh/how-to-encrypt-large-files-in-laravel-293460836ded?source=friends_link&sk=976ab6e5d1cfb52e10c801fe0cb04fca)
- [Part 2: How to encrypt &amp; upload large files to Amazon S3 in Laravel](https://medium.com/@soarecostin/how-to-encrypt-upload-large-files-to-amazon-s3-in-laravel-af88324a9aa?sk=a9a358a3892e898a60448d5314fb3dc0)

### Description

[](#description)

This package will automatically register a facade called `FileVault`. The `FileVault` facade is using the Laravel `Storage` and will allow you to specify a `disk`, just as you would normally do when working with Laravel Storage. All file names/paths that you will have to pass into the package encrypt/decrypt functions are relative to the disk root folder. By default, the `local` disk is used, but you can either specify a different disk each time you call one of `FileVault` methods, or you can set the default disk to something else, by publishing this package's config file.

If you want to change the default `disk` or change the `key`/`cipher` used for encryption, you can publish the config file:

```
php artisan vendor:publish --provider="Brainstud\FileVault\FileVaultServiceProvider"

```

This is the contents of the published file:

```
return [
    /*
     * The default key used for all file encryption / decryption
     * This package will look for a FILE_VAULT_KEY in your env file
     * If no FILE_VAULT_KEY is found, then it will use your Laravel APP_KEY
     */
    'key' => env('FILE_VAULT_KEY', env('APP_KEY')),

    /*
     * The cipher used for encryption.
     * Supported options are AES-128-CBC and AES-256-CBC
     */
    'cipher' => 'AES-256-CBC',

    /*
     * The Storage disk used by default to locate your files.
     */
    'disk' => 'local',
];
```

### Encrypting a file

[](#encrypting-a-file)

The `encrypt` method will search for a file, encrypt it and save it in the same directory, while deleting the original file.

```
public function encrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
```

The `encryptCopy` method will search for a file, encrypt it and save it in the same directory, while preserving the original file.

```
public function encryptCopy(string $sourceFile, string $destFile = null)
```

#### Examples:

[](#examples)

The following example will search for `file.txt` into the `local` disk, save the encrypted file as `file.txt.enc` and delete the original `file.txt`:

```
FileVault::encrypt('file.txt');
```

You can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:

```
FileVault::disk('s3')->encrypt('file.txt');
```

You can also specify a different name for the encrypted file by passing in a second parameter. The following example will search for `file.txt` into the `local` disk, save the encrypted file as `encrypted.txt` and delete the original `file.txt`:

```
FileVault::encrypt('file.txt', 'encrypted.txt');
```

The following examples both achieve the same results as above, with the only difference that the original file is not deleted:

```
// save the encrypted copy to file.txt.enc
FileVault::encryptCopy('file.txt');

// or save the encrypted copy with a different name
FileVault::encryptCopy('file.txt', 'encrypted.txt');
```

### Decrypting a file

[](#decrypting-a-file)

The `decrypt` method will search for a file, decrypt it and save it in the same directory, while deleting the encrypted file.

```
public function decrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
```

The `decryptCopy` method will search for a file, decrypt it and save it in the same directory, while preserving the encrypted file.

```
public function decryptCopy(string $sourceFile, string $destFile = null)
```

#### Examples:

[](#examples-1)

The following example will search for `file.txt.enc` into the `local` disk, save the decrypted file as `file.txt` and delete the encrypted file `file.txt.enc`:

```
FileVault::decrypt('file.txt.enc');
```

If the file that needs to be decrypted doesn't end with the `.enc` extension, the decrypted file will have the `.dec` extention. The following example will search for `encrypted.txt` into the `local` disk, save the decrypted file as `encrypted.txt.dec` and delete the encrypted file `encrypted.txt`:

```
FileVault::decrypt('encrypted.txt');
```

As with the encryption, you can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:

```
FileVault::disk('s3')->decrypt('file.txt.enc');
```

You can also specify a different name for the decrypted file by passing in a second parameter. The following example will search for `encrypted.txt` into the `local` disk, save the decrypted file as `decrypted.txt` and delete the original `encrypted.txt`:

```
FileVault::decrypt('encrypted.txt', 'decrypted.txt');
```

The following examples both achive the same results as above, with the only difference that the original (encrypted) file is not deleted:

```
// save the decrypted copy to file.txt while preserving file.txt.enc
FileVault::decryptCopy('file.txt.enc');

// or save the decrypted copy with a different name, while preserving the file.txt.enc
FileVault::decryptCopy('file.txt.enc', 'decrypted.txt');
```

### Streaming a decrypted file

[](#streaming-a-decrypted-file)

Sometimes you will only want to allow users to download the decrypted file, but you don't need to store the actual decrypted file. For this, you can use the `streamDecrypt` function that will decrypt the file and will write it to the `php://output` stream. You can use the Laravel [`streamDownload` method](https://laravel.com/docs/6.x/responses#file-downloads) (available since 5.6) in order to generate a downloadable response:

```
return response()->streamDownload(function () {
    FileVault::streamDecrypt('file.txt')
}, 'laravel-readme.md');
```

### Using a different key for each file

[](#using-a-different-key-for-each-file)

You may need to use different keys to encrypt your files. You can explicitly specify the key used for encryption using the `key` method.

```
FileVault::key($encryptionKey)->encrypt('file.txt');
```

Please note that the encryption key must be 16 bytes long for the `AES-128-CBC` cipher and 32 bytes long for the `AES-256-CBC` cipher.

You can generate a key with the correct length (based on the cipher specified in the config file) by using the `generateKey` method:

```
$encryptionKey = FileVault::generateKey();
```

```
$fileVault = new AlejandroAPorras\FileVault();
echo $fileVault->echoPhrase('Hello, AlejandroAPorras!');
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Alejandro A](https://github.com/Alejandro-AP00)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance69

Regular maintenance activity

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

735d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/800464c40f2c53161239278eee23923c7d07ac86ec47e0a0d68ea3780c62630d?d=identicon)[AlejandroAP00](/maintainers/AlejandroAP00)

---

Top Contributors

[![Alejandro-AP00](https://avatars.githubusercontent.com/u/6068791?v=4)](https://github.com/Alejandro-AP00 "Alejandro-AP00 (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

---

Tags

laravelfile-vaultAlejandro A

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/alejandro-ap00-file-vault/health.svg)

```
[![Health](https://phpackages.com/badges/alejandro-ap00-file-vault/health.svg)](https://phpackages.com/packages/alejandro-ap00-file-vault)
```

###  Alternatives

[spatie/livewire-filepond

Upload files using Filepond in Livewire components

306452.7k3](/packages/spatie-livewire-filepond)[elegantly/laravel-invoices

Store invoices safely in your Laravel application

23131.8k](/packages/elegantly-laravel-invoices)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[soarecostin/file-vault

192195.0k](/packages/soarecostin-file-vault)[mwguerra/filemanager

A full-featured file manager package for Laravel and Filament v5 with dual operating modes, drag-and-drop uploads, S3/MinIO support, and comprehensive security features.

718.5k1](/packages/mwguerra-filemanager)[codebar-ag/laravel-flysystem-cloudinary

Cloudinary Flysystem v1 integration with Laravel

1224.9k2](/packages/codebar-ag-laravel-flysystem-cloudinary)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
