承接 hxm/media-encrypt 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hxm/media-encrypt

Composer 安装命令:

composer require hxm/media-encrypt

包简介

Media Encrypt

README 文档

README

Laravel 7.x/8.x/9.x/10.x Donate

Media Encrypt

Media Encrypt is a powerful PHP package designed for encrypting sensitive data before storing it in a database. This package provides a secure solution to protect your critical data from unauthorized access.

Installation

You can install this package via Composer with the following command:

  composer require hxm/media-encrypt

After successfully installing the Media Encrypt package, you need to perform some configuration steps to start using it in your project.

  1. Publish Config File: You can publish the configuration file to customize the settings according to your specific requirements by running the following command:
    php artisan vendor:publish --provider="HXM\MediaEncrypt\MediaEncryptServiceProvider" --tag="media-encrypt-config"
    The configuration file will be published to config/media-encrypt.php.
  2. Migrate Database: After the configuration is done, you need to run the migrate command to create the necessary tables in the database:
    php artisan migrate

Usage

To use the Media Encrypt package in your Laravel project, you can refer to the following example code:

  1. Inherit CanMediaEncryptInterface in your Model, then use the HasMediaEncrypt trait in it.

    use Illuminate\Database\Eloquent\Model;
    use HXM\MediaEncrypt\Contracts\CanMediaEncryptInterface;
    use HXM\MediaEncrypt\Traits\HasMediaEncrypt;
    
    class OnlineRequest extends Model implements CanMediaEncryptInterface
    {
        use HasMediaEncrypt;
        #...
    }
  2. Define: To define the field you want to use with the Media Encrypt data, you just need to add it to the $casts attribute in the model itself. Here is the complete code for your Model:

    use Illuminate\Database\Eloquent\Model;
    use HXM\MediaEncrypt\Contracts\CanMediaEncryptInterface;
    use HXM\MediaEncrypt\Traits\HasMediaEncrypt;
    use HXM\MediaEncrypt\Casts\MediaEncryptCast;
    use HXM\MediaEncrypt\Casts\MultiMediaEncryptCast;
    
    class DemoModel extends Model implements CanMediaEncryptInterface
    {
    use HasMediaEncrypt;
    
        protected $appends = ['baseData', 'media', 'media_multi'];
    
        protected $casts = [
            #...
            'baseData' => MediaEncryptCast::class,
            'media' => MediaEncryptCast::class,
            'media_multi' => MultiMediaEncryptCast::class,
        ];
        #...
    }
    
    • The MediaEncryptCast will encode the data into one block.
    • the MultiMediaEncryptCast will understand that your data is stored in the form of an Array, with each sub-element being encrypted separately. If your data is a Media file data array, you must use this cast
  3. Encrypt and store data:

    $model = Demo::first();
    
    $model->baseData = [
        'row' => 1, 
        'column' => 2, 
    ];
    
    $model->media = request()->file('file');
    
    $model->media_multi = [
        'file1' => request()->file('file1'),
        'file2' => request()->get('file2'),
    ];
    $model->save();
  4. Access the encrypted data:

    $model = Demo::first();
    
    dump($model->baseData);
    #@return: instance  HXM\MediaEncrypt\Models\MediaEncrypt
    
    dump($model->baseData->toAray());
    #@return: array:2 [
    #   'row' => 1
    #   'column' => 2
    #   ]
    
    dump($model->media->toUrl());
    #@return: https://baseUrl/encrypt_media/4f03a151-14a9-4234...
    dump($model->media_multi->decrypt());
    #@return: array:2 [
    #   'file1' => https://baseUrl/encrypt_media/4f03a151-14a9-4234...
    #   'file2' => data:image/jpg;base64,/9j/4QAYRXh.........
    #   ]
    • When accessing the property, you will receive an instance of HXM\MediaEncrypt\Models\MediaEncrypt
    • The Media file data will be encrypted and stored in the database, so after decryption, we will return it to the base64 code of the content.
    • Raw data such as text, array will be encrypted and returned unchanged.
  5. Append: If you want to append the decrypted data, simply add the fields you want to the $appends attribute of the Model:

    protected $appends = ['baseData', 'media', 'media_multi'];

Contribution

If you encounter any issues or have any suggestions for improvements, please open an issue on GitHub here. We welcome contributions from the community.

License

The Media Encrypt package is distributed under the MIT License. Please refer to the LICENSE file for detailed information about this license.

Contact

If you have any questions, please feel free to contact us via email at hoanxuanmai@gmail.com. We will try to respond as soon as possible.

HoanXuanMai

We hope that the Media Encrypt package will help you secure your important data effectively. Thank you for using our package!

hxm/media-encrypt 适用场景与选型建议

hxm/media-encrypt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hxm/media-encrypt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hxm/media-encrypt 我们能提供哪些服务?
定制开发 / 二次开发

基于 hxm/media-encrypt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 34
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-10-18