承接 tigr/laravel-compact-encrypter 相关项目开发

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

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

tigr/laravel-compact-encrypter

Composer 安装命令:

composer require tigr/laravel-compact-encrypter

包简介

Encrypter for Laravel that produces much shorter output

README 文档

README

Travis (.org) PHP from Packagist Laravel Version Packagist Version GitHub

Drop-in replacement for Laravel encrypter that produces much more concise and URL-safe output with fallback for encrypted data in old format. For Laravel 5.5+.

Installation

composer require tigr/laravel-compact-encrypter

Then Laravel should do the magic and register our service provider.

Why?

Laravel's encrypter is very inefficient when it comes to space usage. It takes 64 bytes of raw encrypted data and converts it into 192 characters. How?

Laravel stores encrypted data in base64-encoded JSON containing base64 and HEX strings inside. So, base64_encode(json_encode(base64_encode(data) + sha256 hex hash)). Just compare encryption of simple string "hello":

# Laravel Encrypter: 192 characters long
$ artisan tinker
>>> Crypt::encryptString('hello')
=> "eyJpdiI6IlZRZFY5TVZiZVdNSlg3RVdDYTNDbHc9PSIsInZhbHVlIjoiNk9rXC9oV3hZaWEzNE95SU5xMUVHUWc9PSIsIm1hYyI6ImIyZDQ1MTdiODlhMzU1ZjQ1NmU3N2ZlN2I4OGU0Yzc2MjIyZDBkMzAwMGViNjM2OTFlMTZkOGY4MDFjYTg1NDIifQ=="

# add Compact Encrypter
$ composer require tigr/laravel-compact-encrypter

# Compact Encrypter: 70 characters long
$ artisan tinker
>>> Crypt::encryptString('hello')
=> "ABvcrldH1QNn8AgEL_LY-E_Cj04MRWPn3M-kSuvf3DAjzsNfFqC_lUml6iqGkRTjlox2kA"

# Compact Encrypter dropping verification hash: 53 characters long
>>> Crypt::encryptString('hello', false)
=> "z4zztewR8vQ7QId_P6diDRW2DvVPhwf4xh8gNss4G1o"

Who cares?

First, if you have some encrypted cookies, you might easily run into 400 errors with "header too long" from your server, or from load-balancing/DDoS-protection proxies in the middle. On average, Compact Encrypter produces 25-275% more compact output or up to 360% more compact with hash dropped.

Second, you might want to use self-contained tokens in URLs (no need for token DB), but guess what, 192 characters some of which are URL-escaped are way too ugly.

How does it work?

  1. No intermediate base64 or hex encoding, all data is raw binary.
  2. No JSON, use pack()/unpack().
  3. Use URL-safe version of base64 (drop trailing '=', replace '/+' with '-_').
  4. For hashing, use SHA1 instead of SHA256. I know, I know, but for real-world purposes SHA1 is still good enough.
  5. Allow dropping Mac (validation hash) whatsoever in case you want it really short.
  6. And provide fallback decryption if we ever encounter data encrypted with Laravel Encryptor

tigr/laravel-compact-encrypter 适用场景与选型建议

tigr/laravel-compact-encrypter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 tigr/laravel-compact-encrypter 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-14