kba-team/data-protection
Composer 安装命令:
composer require kba-team/data-protection
包简介
Deterministic one-way encryption of unique sensitive data.
关键字:
README 文档
README
The goal of this class is to encrypt unique sensitive information, like social security numbers, without the possibility
to decrypt it afterwards but still be able to search for it using equals and not equals operators.
Scenario
A persons data in the database contains a social security number. This kind of data is sensitive because, in case of a security breach, a criminal can use it to assume the identities of the people stored in the breached database. Therefore this kind of information needs to be protected.
In this scenario the social security number is never actually displayed or processed. It is used to identify a unique person even if other stored data of that person changes over time, like a change of name in case of a marriage.
It is assumed that the social security number won't appear twice in the database.
In order to uniquely identify a person, it still has to be possible to search for the social security number, even
though this information has been encrypted. The typical search patterns are either equals, in case a person needs to
be uniquely identified, or not equals to avoid duplicate entries for the same person in the database.
Simply creating a hash value of that information, or a hash value with a static salt, won't work, because an attacker can create a rainbow table of all possible iterations and match their hashed values against the ones stored in the database.
Creating a salted hash value, like the ones used for passwords, won't work because it has to be possible to search a
database of thousands of entries. In order to perform an equals search, the information has to be hashed using all
prior used salt values. An not equals search in that manner won't reliably determine whether a person is not in
the database.
Solution
The solution to safely store sensitive information is to encrypt it in a deterministic way, without the possibility to decrypt the information afterwards.
A safe encryption consists of a secret key and an initialization vector which guarantees the encrypted value is unique.
Based on the information found in question 59580 on Stack Exchange ciphers in CBC mode with an initialization vector derived from the plain text match the requirement of a deterministically encrypted information.
In order to generate the same encrypted value each time, the key and the cipher algorithm used, need to stay the same for the given database, but the key needs to be different for different databases. This will make it harder for an attacker to create a rainbow table.
Downfall
In case the secret encryption key is breached, the encrypted data is still safe as long as computing power doesn't allow for a rainbow table based on all possible social security numbers encrypted with the secret key to be created within a reasonable amount of time.
Usage
Include this package using composer.
composer require kba-team/data-protection: "^1.0"
Securely generate a secret key.
<?php use kbATeam\DataProtection\SecureSearch; //generate a key $key_hex = SecureSearch::generateKey(); //print the result printf('%s%s', $key_hex, PHP_EOL);
Encrypt the data.
<?php use kbATeam\DataProtection\SecureSearch; //convert the key to its raw version $key_raw = hex2bin($key_hex); //set the social security number $ssn = 1234567890; //encrypt the social security number $ssn_encrypted = SecureSearch::encrypt($ssn, $key_raw); //print the result printf('%s%s', $ssn_encrypted, PHP_EOL);
Development
Clone repository and install all requirements using composer.
git clone https://github.com/the-kbA-team/data-protection.git composer install
Run tests.
vendor/bin/phpunit --
MIT License
MIT License
Copyright (c) 2018 the-kbA-team
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kba-team/data-protection 适用场景与选型建议
kba-team/data-protection 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.15k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「encryption」 「deterministic」 「Ssn」 「Social security number」 「searchable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kba-team/data-protection 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kba-team/data-protection 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kba-team/data-protection 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
A simple PHP class to encrypt a string and decrypt an encrypted string
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
FormalTheory is a library that allows for manipulation and conversion of NFAs, DFAs and Regular Expressions.
统计信息
- 总下载量: 6.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-24