wubbajack/filecrypt
Composer 安装命令:
composer require wubbajack/filecrypt
包简介
PHP package for encrypted and decrypting files
README 文档
README
A PHP package for encrypting and decrypting files. Also offers the possibility of streaming decryption of file data.
DISCLAIMER
This package is still a work in progress. This means that Method signatures and return values will change over time. Implementation specifics will also change.
If you do wish to use or test this package, do so with care. Everything has been "humanly" tested, still working on writing proper tests.
If you wish to contribute please start of with creating new issues before sending in pull requests.
Info
The goal of this project is to offer a simple method of working with encrypted files in PHP. There are some great (shell) tools out there that can do the same thing. But when decrypting streams becomes necessary, I've found it to be more and more difficult to implement properly.
This package uses stream filters for encryption and decryption, using box standard mcrypt ciphers. This allows for streaming decryption.
Default encryption
By default the package uses the AES encryption standard. This means that files that have been encrypted with this package can be decrypted by any other tool that supports AES, provided you have a string representation of the used Key and IV.
Installation and Requirements
You can install the package easily using composer
$ composer require wubbajack/filecrypt
The minimum requirements are:
- PHP 5.6
- Mcrypt extension
Test
To test this package just run
$ php vendor/bin/phpunit
Examples and usage
Below are some examples on how to use the FileEncrypter class
Encrypting files
<?php /** * This creates a new instance of the FileEncrypter. By default * it uses RIJNDAEL-128 with a 16 bit block size, which corresponds with the AES standard. */ $fileEncrypter = new Wubbajack\Encryption\FileEncrypter($key); $source_file = '/path/to/source/file.jpg'; $target_file = '/path/to/encryted/file.enc'; /** * Encrypts a source file to a target file and returns an EncryptedFile instance */ $encryptedFile = $fileEncrypter->encrypt($source_file, $target_file);
Decrypting files
<?php /** * In this example we assume that we already have an EncryptedFile instance * where we can extract the required information from */ $fileCrypt = new Wubbajack\Encryption\FileEncrypter($key); $target_file = '/path/to/decrypted/file.jpg'; // Decrypts our encrypted file and returns the path to the file $fileCrypt->decrypt($encryptedFile, $target_file);
Streaming decryption
<?php /** * In this example we also assume that we already have an EncryptedFile instance */ $fileCrypt = new Wubbajack\Encryption\FileEncrypter($key); /** * The streamDecrypt method allows you to supply a callback and manipulate or echo the data. * This can be very useful when streaming encrypted media back to a client. * * The padding is automatically stripped from the data, so no worries there. */ $fileCrypt->streamDecrypt($encryptedFile, function ($data, $stream) { echo $data; if (feof($stream)) { // I have finished! } });
wubbajack/filecrypt 适用场景与选型建议
wubbajack/filecrypt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 01 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wubbajack/filecrypt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wubbajack/filecrypt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 29
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-02