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
This package will automatically register a facade called `FileVault`.
25
+
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.
26
+
27
+
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
38
+
* This package will look for a FILE_VAULT_KEY in your env file
39
+
* If no FILE_VAULT_KEY is found, then it will use your Laravel APP_KEY
40
+
*/
41
+
'key' => env('FILE_VAULT_KEY', env('APP_KEY')),
42
+
43
+
/*
44
+
* The cipher used for encryption.
45
+
* Supported options are AES-128-CBC and AES-256-CBC
46
+
*/
47
+
'cipher' => 'AES-256-CBC',
48
+
49
+
/*
50
+
* The Storage disk used by default to locate your files.
51
+
*/
52
+
'disk' => 'local',
53
+
];
54
+
```
55
+
26
56
27
57
### Encrypting a file
28
58
29
-
The `encrypt` method will search for a file, encrypt it and save it in the same directory.
59
+
The `encrypt` method will search for a file, encrypt it and save it in the same directory, while deleting the original file.
30
60
31
61
```php
32
62
public function encrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
33
63
```
34
64
65
+
The `encryptCopy` method will search for a file, encrypt it and save it in the same directory, while preserving the original file.
66
+
67
+
```php
68
+
public function encryptCopy(string $sourceFile, string $destFile = null)
69
+
```
70
+
71
+
35
72
#### Examples:
36
73
37
74
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`:
38
75
```php
39
-
FileVault::encrypt("file.txt");
76
+
FileVault::encrypt('file.txt');
40
77
```
41
78
42
79
You can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:
43
80
```php
44
-
FileVault::disk('s3')->encrypt("file.txt");
81
+
FileVault::disk('s3')->encrypt('file.txt');
45
82
```
46
83
47
-
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`:
84
+
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`:
48
85
```php
49
-
FileVault::encrypt("file.txt", "encrypted.txt");
86
+
FileVault::encrypt('file.txt', 'encrypted.txt');
50
87
```
51
88
52
89
The following examples both achive the same results as above, with the only difference that the original file is not deleted:
53
90
```php
54
91
// save the encrypted copy to file.txt.enc
55
-
FileVault::encryptCopy("file.txt");
92
+
FileVault::encryptCopy('file.txt');
56
93
57
94
// or save the encrypted copy with a different name
The `decrypt` method will search for a file, decrypt it and save it in the same directory
100
+
The `decrypt` method will search for a file, decrypt it and save it in the same directory, while deleting the encrypted file.
101
+
102
+
```php
103
+
public function decrypt(string $sourceFile, string $destFile = null, $deleteSource = true)
104
+
```
105
+
106
+
The `decryptCopy` method will search for a file, decrypt it and save it in the same directory, while preserving the encrypted file.
107
+
108
+
```php
109
+
public function decryptCopy(string $sourceFile, string $destFile = null)
110
+
```
111
+
112
+
#### Examples:
64
113
114
+
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`:
115
+
```php
116
+
FileVault::decrypt('file.txt.enc');
117
+
```
118
+
119
+
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`:
120
+
```php
121
+
FileVault::decrypt('encrypted.txt');
122
+
```
123
+
124
+
As with the encryption, you can also specify a different `disk`, just as you would normally with the Laravel `Storage` facade:
125
+
```php
126
+
FileVault::disk('s3')->decrypt('file.txt.enc');
127
+
```
128
+
129
+
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`:
0 commit comments