spomky-labs/php-aes-gcm
Composer 安装命令:
composer require spomky-labs/php-aes-gcm
包简介
AES GCM (Galois Counter Mode) PHP implementation.
README 文档
README
The Release Process
The release process is described here.
Prerequisites
It has been successfully tested using PHP 5.4 to PHP 7.1, HHVM and nightly branches.
If you use PHP 7.1+, this library has very good performance. If you do not use PHP 7.1+, we highly recommend you to install the PHP Crypto extension. This extension drastically increase the performance of this library. With our pure PHP method, you will have low performance.
Installation
The preferred way to install this library is to rely on Composer:
composer require "spomky-labs/php-aes-gcm"
How to use
<?php use AESGCM\AESGCM; // The Key Encryption Key $K = hex2bin('feffe9928665731c6d6a8f9467308308feffe9928665731c'); // The data to encrypt (can be null for authentication) $P = hex2bin('d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39'); // Additional Authenticated Data $A = hex2bin('feedfacedeadbeeffeedfacedeadbeefabaddad2'); // Initialization Vector $IV = hex2bin('cafebabefacedbaddecaf888'); // $C is the encrypted data ($C is null if $P is null) // $T is the associated tag list($C, $T) = AESGCM::encrypt($K, $IV, $P, $A); // The value of $C should be hex2bin('3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710') // The value of $T should be hex2bin('2519498e80f1478f37ba55bd6d27618c') $P = AESGCM::decrypt($K, $IV, $C, $A, $T); // The value of $P should be hex2bin('d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39')
Appended Tag
Some implementations of this cypher may append the tag at the end of the ciphertext. This is commonly used by the Java implementation for example.
This library provides an easy way to produce such a ciphertext and read it.
<?php use AESGCM\AESGCM; // The values $K, $P, $A, $IV hereafter have the same meaning as above // $C is the encrypted data with the appended tag $C = AESGCM::encryptAndAppendTag($K, $IV, $P, $A); // The value of $C should be hex2bin('3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda27102519498e80f1478f37ba55bd6d27618c') $P = AESGCM::decryptWithAppendedTag($K, $IV, $C, $A); // The value of $P should be hex2bin('d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b392519498e80f1478f37ba55bd6d27618c')
Tag Length
By default the tag length is 128 bits. This value is highly recommended, however you may need to use another tag length. As per the cypher specification, the tag length could be 128, 120, 112, 104 or 96 bits.
<?php use AESGCM\AESGCM; // The values $K, $P, $A, $IV hereafter have the same meaning as above $TL = 96; // In this example the tag length will be 96 bits list($C, $T) = AESGCM::encrypt($K, $IV, $P, $A, $TL); // The value of $C should be hex2bin('3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710') // The value of $T should be hex2bin('2519498e80f1478f37ba55bd')
The tag length is automatically calculated during the decryption operation with the method AESGCM::decrypt.
However, if the tag is appended at the end of the ciphertext and if it is not 128 bits, then it must be set:
<?php // The values $K, $IV, $C, $A hereafter have the same meaning as above $TL = 96; // In this example the tag length will be 96 bits $P = AESGCM::decryptWithAppendedTag($K, $IV, $C, $A, $TL);
Support
I bring solutions to your problems and answer your questions.
If you really love that project and the work I have done or if you want I prioritize your issues, then you can help me out for a couple of 🍻 or more!
Contributing
Requests for new features, bug fixed and all other ideas to make this library useful are welcome. The best contribution you could provide is by fixing the opened issues where help is wanted
Please make sure to follow these best practices.
Benchmark
In the test folder, a little script to run encryption and decryption benchmarks is available.
You can run it on your environment to check how many time the encryption/decryption operations take.
php ./tests/Benchmark.php
Licence
This library is release under MIT licence.
spomky-labs/php-aes-gcm 适用场景与选型建议
spomky-labs/php-aes-gcm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.03M 次下载、GitHub Stars 达 71, 最近一次更新时间为 2016 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「aes」 「gcm」 「Galois Counter Mode」 「AES-GCM」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spomky-labs/php-aes-gcm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spomky-labs/php-aes-gcm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spomky-labs/php-aes-gcm 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library for Galois/Counter Mode encryption with AES.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Yii 2 Apns and Gcm together
Firebase cloud messaging http v1 php
AES cipher - FIPS 192 compliant
Standalone PHP library for easy devices notifications push.
统计信息
- 总下载量: 5.03M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 71
- 点击次数: 25
- 依赖项目数: 25
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-28