承接 evit/php-gm-crypto 相关项目开发

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

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

evit/php-gm-crypto

Composer 安装命令:

composer require evit/php-gm-crypto

包简介

Fully compatible with the sm4-cbc and sm4-ecb state secret SM algorithms of openssl. When openssl >= 1.1.1 supports the state secret algorithm, directly call openssl for SM4 encryption and decryption, otherwise call the custom algorithm.

README 文档

README

  • PHP后端:composer require evit/php-gm-crypto
  • 对应前端:npm install evit-gm-crypt

php-gm-crypto

PHP Style GuideLicense: MIT

基于PHP的国密加密算法实现。

Implement of Chinese encrypt algorithm in PHP.

完全兼容openssl的sm4-cbc和sm4-ecb国密SM算法,openssl >= 1.1.1支持国密算法时直接调用openssl进行SM4加解密,否则调用自定义算法。

Fully compatible with the sm4-cbc and sm4-ecb state secret SM algorithms of openssl. When openssl >= 1.1.1 supports the state secret algorithm, directly call openssl for SM4 encryption and decryption, otherwise call the custom algorithm.

新增SM3实现,openssl >= 1.1.1支持国密算法时直接调用openssl进行SM3杂凑,否则调用自定义算法。

openssl_encryptopenssl_decrypt保持一致性,当密码长度小于16时,静默填充NUL;当密码长度大于16时,静默截断。

Consistent with openssl_encrypt and openssl_decrypt, NUL is silently filled when the password length is less than 16; When the password length is greater than 16, it is truncated silently.

要使用openssl国密算法,openssl库需 >= 1.1.1。

To use openssl state secret algorithm, openssl library needs > = 1.1.1.

Roadmap

  • SM4
  • SM3
  • SM2

Documentation

Install

composer require evit/php-gm-crypto

SM4

Init

<?php
// If you are using a framework that does not support psr-4 autoloader, you need to explicitly import package from the vendor directory.
require_once __DIR__ . "/vendor/autoload.php";

use Evit\PhpGmCrypto\Encryption\EvitSM4Encryption;

$config = [
    // mode string 'cbc' or 'ecb' is supported, default is 'cbc'.
    'mode'  => 'cbc',
    // password, will be processed by substr(md5($key), 0, 16) if $config['hash']
    'key'   => '{replace-your-key-here}',
    // the iv used by 'cbc' mode, will be will be processed by substr(md5($iv), 0, 16) if $config['hash']
    'iv'    => '{replace-your-iv-here}',
    // weather do md5 to key and iv or not
    'hash'  => false
];

$sm4 = new EvitSM4Encryption($config);

Encrypt

// Encrypt
$start = microtime(true);
$encypted = $sm4->sm4encrypt('{replace-your-plaintext-here}');
$end = microtime(true);
var_dump('Encrypt time elapsed:' . number_format($end - $start, 8) . ' s');
var_dump("Cipher text:{$encypted}");

Decrypt

// Decrypt
$decStart = microtime(true);
$decrypted = $sm4->sm4decrypt($encypted);
$end = microtime(true);
var_dump('Decrypt time elapsed:' . number_format($end - $decStart, 8) . ' s');
var_dump("Plain text:{$decrypted}");

Algorithm

// Determine whether openssl library is used
$algorithm = $sm4->isOpenssl() ? 'openssl' : 'php-gm-crypto';
var_dump("Algrithm is:{$algorithm}");
var_dump('Total time elapsed:' . number_format($end - $start, 8) . ' s');

SM3

// If you are using a framework that does not support psr-4 autoloader, you need to explicitly import package from the vendor directory.
require_once __DIR__ . "/vendor/autoload.php";

use Evit\PhpGmCrypto\Encryption\EvitSM3Encryption;

$sm3 = new EvitSM3Encryption();
$input = 'abc';

$output = $sm3->sm3($input);
var_dump("SM3 hash result of '{$input}' is '{$output}'");

对应的前端安装

npm install evit-gm-crypt

传送门:evit-gm-crypt

License

MIT

evit/php-gm-crypto 适用场景与选型建议

evit/php-gm-crypto 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.47k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2022 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 evit/php-gm-crypto 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 4.47k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 12
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-07