{"id":29962035,"url":"https://github.com/soarecostin/file-vault","last_synced_at":"2025-08-03T23:44:13.312Z","repository":{"id":41364483,"uuid":"221933072","full_name":"soarecostin/file-vault","owner":"soarecostin","description":"A Laravel package for encrypting and decrypting files of any size","archived":false,"fork":false,"pushed_at":"2023-01-13T09:13:54.000Z","size":54,"stargazers_count":192,"open_issues_count":23,"forks_count":70,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-15T04:22:35.230Z","etag":null,"topics":["cbc","decryption","encryption","file","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soarecostin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-15T13:48:48.000Z","updated_at":"2025-07-07T14:38:37.000Z","dependencies_parsed_at":"2023-02-09T15:16:51.277Z","dependency_job_id":null,"html_url":"https://github.com/soarecostin/file-vault","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/soarecostin/file-vault","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarecostin%2Ffile-vault","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarecostin%2Ffile-vault/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarecostin%2Ffile-vault/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarecostin%2Ffile-vault/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soarecostin","download_url":"https://codeload.github.com/soarecostin/file-vault/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarecostin%2Ffile-vault/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268629866,"owners_count":24281173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cbc","decryption","encryption","file","laravel","php"],"created_at":"2025-08-03T23:44:05.801Z","updated_at":"2025-08-03T23:44:13.175Z","avatar_url":"https://github.com/soarecostin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# File encryption / decryption in Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/soarecostin/file-vault.svg?style=flat-square)](https://packagist.org/packages/soarecostin/file-vault)\n[![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/soarecostin/file-vault/master.svg?style=flat-square)](https://travis-ci.org/soarecostin/file-vault)\n[![Quality Score](https://img.shields.io/scrutinizer/g/soarecostin/file-vault.svg?style=flat-square)](https://scrutinizer-ci.com/g/soarecostin/file-vault)\n[![StyleCI](https://styleci.io/repos/221933072/shield)](https://styleci.io/repos/221933072)\n[![Total Downloads](https://img.shields.io/packagist/dt/soarecostin/file-vault.svg?style=flat-square)](https://packagist.org/packages/soarecostin/file-vault)\n\nWith 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.\n\n\n## Installation and usage\n\nThis package requires PHP 7.2 and Laravel 5.8 or higher.  \n\nYou can install the package via composer:\n\n```bash\ncomposer require soarecostin/file-vault\n```\n\n## Usage\n\n### Tutorials\nFor a detailed description of how to encrypt files in Laravel using this package, please see the following articles:\n- [Part 1: How to encrypt large files in Laravel](https://medium.com/swlh/how-to-encrypt-large-files-in-laravel-293460836ded?source=friends_link\u0026sk=976ab6e5d1cfb52e10c801fe0cb04fca)\n- [Part 2: How to encrypt \u0026 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)\n\n### Description\nThis 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.\n\nIf you want to change the default `disk` or change the `key`/`cipher` used for encryption, you can publish the config file:\n\n```\nphp artisan vendor:publish --provider=\"SoareCostin\\FileVault\\FileVaultServiceProvider\"\n```\n\nThis is the contents of the published file:\n``` php\nreturn [\n    /*\n     * The default key used for all file encryption / decryption\n     * This package will look for a FILE_VAULT_KEY in your env file\n     * If no FILE_VAULT_KEY is found, then it will use your Laravel APP_KEY\n     */\n    'key' =\u003e env('FILE_VAULT_KEY', env('APP_KEY')),\n\n    /*\n     * The cipher used for encryption.\n     * Supported options are AES-128-CBC and AES-256-CBC\n     */\n    'cipher' =\u003e 'AES-256-CBC',\n\n    /*\n     * The Storage disk used by default to locate your files.\n     */\n    'disk' =\u003e 'local',\n];\n```\n\n\n### Encrypting a file\n\nThe `encrypt` method will search for a file, encrypt it and save it in the same directory, while deleting the original file.\n\n``` php\npublic function encrypt(string $sourceFile, string $destFile = null, $deleteSource = true)\n```\n\nThe `encryptCopy` method will search for a file, encrypt it and save it in the same directory, while preserving the original file.\n\n``` php\npublic function encryptCopy(string $sourceFile, string $destFile = null)\n```\n\n\n#### Examples:\n\nThe 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`:\n``` php\nFileVault::encrypt('file.txt');\n```\n\nYou can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:\n``` php\nFileVault::disk('s3')-\u003eencrypt('file.txt');\n```\n\nYou 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`:\n``` php\nFileVault::encrypt('file.txt', 'encrypted.txt');\n```\n\nThe following examples both achive the same results as above, with the only difference that the original file is not deleted:\n``` php\n// save the encrypted copy to file.txt.enc\nFileVault::encryptCopy('file.txt');\n\n// or save the encrypted copy with a different name\nFileVault::encryptCopy('file.txt', 'encrypted.txt');\n```\n\n### Decrypting a file\n\nThe `decrypt` method will search for a file, decrypt it and save it in the same directory, while deleting the encrypted file.\n\n``` php\npublic function decrypt(string $sourceFile, string $destFile = null, $deleteSource = true)\n```\n\nThe `decryptCopy` method will search for a file, decrypt it and save it in the same directory, while preserving the encrypted file.\n\n``` php\npublic function decryptCopy(string $sourceFile, string $destFile = null)\n```\n\n#### Examples:\n\nThe 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`:\n``` php\nFileVault::decrypt('file.txt.enc');\n```\n\nIf 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`:\n``` php\nFileVault::decrypt('encrypted.txt');\n```\n\nAs with the encryption, you can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:\n``` php\nFileVault::disk('s3')-\u003edecrypt('file.txt.enc');\n```\n\nYou 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`:\n``` php\nFileVault::decrypt('encrypted.txt', 'decrypted.txt');\n```\n\nThe following examples both achive the same results as above, with the only difference that the original (encrypted) file is not deleted:\n``` php\n// save the decrypted copy to file.txt while preserving file.txt.enc\nFileVault::decryptCopy('file.txt.enc');\n\n// or save the decrypted copy with a different name, while preserving the file.txt.enc\nFileVault::decryptCopy('file.txt.enc', 'decrypted.txt');\n```\n\n### Streaming a decrypted file\n\nSometimes 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:\n\n``` php\nreturn response()-\u003estreamDownload(function () {\n    FileVault::streamDecrypt('file.txt')\n}, 'laravel-readme.md');\n```\n\n### Using a different key for each file\n\nYou may need to use different keys to encrypt your files. You can explicitly specify the key used for encryption using the `key` method.\n\n``` php\nFileVault::key($encryptionKey)-\u003eencrypt('file.txt');\n```\n\nPlease 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.\n\nYou can generate a key with the correct length (based on the cipher specified in the config file) by using the `generateKey` method:\n\n``` php\n$encryptionKey = FileVault::generateKey();\n```\n\n## Testing\n\nRun the tests with:\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email soarecostin@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Costin Soare](https://github.com/soarecostin)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## Laravel Package Boilerplate\n\nThis package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarecostin%2Ffile-vault","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoarecostin%2Ffile-vault","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarecostin%2Ffile-vault/lists"}