You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-33Lines changed: 66 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,33 +1,58 @@
1
1
# File encryption / decryption in Laravel
2
2
3
-
[](https://packagist.org/packages/soarecostin/file-vault)
## ⚠️ This is a fork of [soarecostin/file-vault](https://github.com/soarecostin/file-vault) ⚠️
9
4
10
-
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.
5
+
We forked the repository due to abandoned state of the project in order to fix some issues we were having:
11
6
7
+
-[Fix a S3 bug returning chunk with a different than expected chunk size](https://github.com/soarecostin/file-vault/pull/20)
8
+
- Add Laravel 9, PHP 8 and Flysystem v23 support
9
+
10
+
Refer to the original repo for the history of opened and closed issues
11
+
12
+
The namespace has been changed from `Soarecostin/FileVault` to `Tiknil/FileVault` to allow parallel usage of both versions
13
+
14
+
---
15
+
16
+
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.
12
17
13
18
## Installation and usage
14
19
15
-
This package requires PHP 7.2 and Laravel 5.8 or higher.
20
+
This package requires PHP 7.2 and Laravel 5.8 or higher.
16
21
17
-
You can install the package via composer:
22
+
You can install the original package via composer:
18
23
19
24
```bash
20
25
composer require soarecostin/file-vault
21
26
```
22
27
28
+
or this fork by adding the reference to the github repo in your composer.json:
29
+
30
+
```php
31
+
"repositories": [
32
+
{
33
+
"type": "vcs",
34
+
"url": "https://github.com/tiknil/file-vault"
35
+
}
36
+
],
37
+
```
38
+
39
+
and then
40
+
41
+
```bash
42
+
composer require tiknil/file-vault
43
+
```
44
+
23
45
## Usage
24
46
25
47
### Tutorials
48
+
26
49
For a detailed description of how to encrypt files in Laravel using this package, please see the following articles:
27
-
-[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)
28
-
-[Part 2: How to encrypt & 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)
50
+
51
+
-[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)
52
+
-[Part 2: How to encrypt & 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)
29
53
30
54
### Description
55
+
31
56
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.
32
57
33
58
If you want to change the default `disk` or change the `key`/`cipher` used for encryption, you can publish the config file:
* The default key used for all file encryption / decryption
@@ -59,41 +85,43 @@ return [
59
85
];
60
86
```
61
87
62
-
63
88
### Encrypting a file
64
89
65
90
The `encrypt` method will search for a file, encrypt it and save it in the same directory, while deleting the original file.
66
91
67
-
```php
92
+
```php
68
93
public function encrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
69
94
```
70
95
71
96
The `encryptCopy` method will search for a file, encrypt it and save it in the same directory, while preserving the original file.
72
97
73
-
```php
98
+
```php
74
99
public function encryptCopy(string $sourceFile, string $destFile = null)
75
100
```
76
101
77
-
78
102
#### Examples:
79
103
80
104
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`:
81
-
```php
105
+
106
+
```php
82
107
FileVault::encrypt('file.txt');
83
108
```
84
109
85
110
You can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:
86
-
```php
111
+
112
+
```php
87
113
FileVault::disk('s3')->encrypt('file.txt');
88
114
```
89
115
90
116
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`:
91
-
```php
117
+
118
+
```php
92
119
FileVault::encrypt('file.txt', 'encrypted.txt');
93
120
```
94
121
95
122
The following examples both achive the same results as above, with the only difference that the original file is not deleted:
The `decrypt` method will search for a file, decrypt it and save it in the same directory, while deleting the encrypted file.
107
135
108
-
```php
136
+
```php
109
137
public function decrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
110
138
```
111
139
112
140
The `decryptCopy` method will search for a file, decrypt it and save it in the same directory, while preserving the encrypted file.
113
141
114
-
```php
142
+
```php
115
143
public function decryptCopy(string $sourceFile, string $destFile = null)
116
144
```
117
145
118
146
#### Examples:
119
147
120
148
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`:
121
-
```php
149
+
150
+
```php
122
151
FileVault::decrypt('file.txt.enc');
123
152
```
124
153
125
154
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`:
126
-
```php
155
+
156
+
```php
127
157
FileVault::decrypt('encrypted.txt');
128
158
```
129
159
130
160
As with the encryption, you can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:
131
-
```php
161
+
162
+
```php
132
163
FileVault::disk('s3')->decrypt('file.txt.enc');
133
164
```
134
165
135
166
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`:
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:
0 commit comments