craftwork/id-obfuscator
Composer 安装命令:
composer require craftwork/id-obfuscator
包简介
A base converter to obfuscate database IDs in front end applications
README 文档
README
A simple encoder to obfuscate database IDs.
This is particularly useful when you don't want to expose sensitive information about your application, for instance the number of users or orders.
Imagine having URLs like these:
http://example.com/user/5
http://example.com/order/2835
then you can convert them into:
http://example.com/user/J
http://example.com/order/3l
Note
This is not an encryption library and should not be used for security purposes.
It is not advisable saving encoded numbers but encoding and decoding IDs on the fly.
You can use a custom character set and a salt to shuffle the characters. Keep the salt private.
It is not advisable to change these at run time as some users might share or bookmark links. To ensure users don't end up on broken links always use the same character set and salt. If the links are restricted to logged in users it might be a good idea to use a user specific salt, such as a uuid.
Installation
$ composer require craftwork/id-obfuscator
Requirements
PHP 7.0.
Usage
$salt = 'test'; $obfuscator = new IdObfuscator($salt); $obfuscator->encode(10); // m $obfuscator->encode(1234566); // oK-k $obfuscator->decode('m'); // 10 $obfuscator->decode('oK-k'); // 1234566
Character sets
The default character set is bcdefghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ1234567890-_. An additional character set
is also built in which only uses lowercase hexadecimal characters (CharacterSet::ofHexCharacters()).
You can provide your own character set if you want to either limit the encoding to certain characters or use different characters. Characters need to be ASCII and the character set must be at least two characters long and not contain any duplicates.
$salt = 'test'; $customCharacterSet = CharacterSet::ofCustomCharacters('ambidextrously'); $obfuscator = new IdObfuscator($salt, $customCharacterSet); $obfuscator->encode(16); // 10 (string)
craftwork/id-obfuscator 适用场景与选型建议
craftwork/id-obfuscator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 90 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 craftwork/id-obfuscator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 craftwork/id-obfuscator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 90
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-24