steefdw/filecrypt
Composer 安装命令:
composer require steefdw/filecrypt
包简介
FileCrypt is a simple yet powerful PHP package designed to help developers easily encrypt and decrypt files. This library utilizes the Libsodium cryptography library, ensuring strong encryption standards.
关键字:
README 文档
README
FileCrypt is a simple yet powerful PHP package designed to help developers easily encrypt and decrypt files. This library utilizes the Libsodium cryptography library, ensuring strong encryption standards.
Cypto is hard, but encrypting / decrypting sensitive files shouldn't be.
Installation
composer require steefdw/filecrypt
Usage
How to use FileCrypt:
- First, generate a key and store it somewhere safe
- After that you can easily encrypt of decrypt files
Tip: if you store the files, and you persist the S3/file paths in a database, you could also generate a key for each file, and save that key in your database alongside the S3/file path.
Generating a Secret Key
You can generate a new secret key using the FileCrypt::generateKey() method:
$secretKey = FileCrypt::generateKey();
Encrypting files
FileCrypt::encrypt(
'path/to/input-file.txt',
'path/to/output-file.encrypted',
$secretKey
);
Decrypting files
FileCrypt::decrypt(
'path/to/input-file.encrypted',
'path/to/output-file.decrypted',
$secretKey
);
Storing the key
FileCrypt::generateKey() generates a binary sting, so expect something like: ���m���yS'������H�&�@�'4%�\F�3.
And not a key like: abcdefg1234567890hijkjlmnopk.
So, if you want to store the key as text somewhere --like putting it in an .env variable-- save it as:
$secretKey = FileCrypt::generateKey();
$base64EncodedStoredSecret = base64_encode($secretKey);
// Don't forget to decode it before using:
$secretKey = base64_decode($base64EncodedStoredSecret);
You can find a simple working example in example.php.
Testing
composer test
Or:
make test
Contributing
- make sure the code validation succeeds. You can run it with
make validate. - make sure all tests succeed. You can run them with
make test. - make sure all code is tested.
License
FileCrypt is released under the MIT license. Please see Licence File for more information.
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-21