assistenzde/simple-cryptographic-bundle
Composer 安装命令:
composer require assistenzde/simple-cryptographic-bundle
包简介
A simple cryptographic service to encode/decode an input string with openssl_encrypt methods like aes128, aes256, blowfish and other cipher methods.
关键字:
README 文档
README
The SimpleCryptographicService class contains method to encrypt/decrypt phrases with symmetric encryption. With the usage of OpenSSL each encoding of the same phrase results in a different encoded string.
Quick example usage:
$cryptographicService = new SimpleCryptographicService('$ecr3t'); $encryptedString1 = $cryptographicService->encrypt('Hello world!'); // some encrypted string, i.e. 'ABCDEFG' echo $cryptographicService->decrypt($encryptedString1); // outputs 'Hello world!' $encryptedString2 = $cryptographicService->encrypt('Hello world!'); // some encrypted string, i.e. 'HIJKLMNOP' echo $cryptographicService->decrypt($encryptedString2); // outputs 'Hello world!'
This library can be used easily in Symfony projects but also in non-Symfony projects.
Table of Contents
Requirements
The usage of PHP ≥ v7.4 and Symfony ≥ 5 is recommended.
Installation
Please install via composer.
composer require assistenzde/simple-cryptographic-bundle
The bundle will be automatically added to your bundles.yaml configuration.
Symfony Configuration
By default the bundle depends on the APP_SECRET environment variable and uses the aes-256-ctr cipher method. If you want to use a custom cipher key OR a customer cipher method create the
config/packates/simple-cryptographic-bundle.yaml configuration file and set the related values.
simple-cryptographic-bundle.yaml:
simple-cryptographic-bundle.yaml: # set a custom cipher key or comment out to use the default value # default is %kernel.secret% (which contains the APP_SECRET value) key: My-cu5t0m-c1ph3r-k3y # set a custom cipher method or comment out to use the default value # default is aes-256-ctr cipher: camellia-128-ofb
Usage
Use dependency injection to access the cryptographic service.
<?php namespace MyNamespace; use Assistenzde\SimpleCryptographicBundle\Service\SimpleCryptographicService; /** * Class AuthenticationSubscriber */ final class MyClass { /** * the crypto service to encode/dedoce strings * * @var SimpleCryptographicService */ protected SimpleCryptographicService $simpleCryptographicService; /** * MyClass constructor * * @param SimpleCryptographicService $simpleCryptographicService */ public function __construct(SimpleCryptographicService $simpleCryptographicService) { $this->simpleCryptographicService = $simpleCryptographicService; } /** * */ public function doSomething() { // do some calculation and get a user token // encrypt the user token $encryptedUserToken = $this->simpleCryptographicService->encrypt($userToken); // and do some more stuff, // esp. use the encrypted token (i.e. as request parameter or to save in a file) // derypt the encrypted stuff $userToken = $this->simpleCryptographicService->decrypt($encryptedUserToken); } }
We suggest using the public methods
- SimpleCryptographicService::encrypt and
- SimpleCryptographicService::decrypt.
To temporarily use custom settings switch to the static methods
- SimpleCryptographicService::EncryptWithMethod and/or
- SimpleCryptographicService::DecryptWithMethod.
Credits
A big thank you to stackoverflow's user Scott Arciszewski for the explanations in of the https://stackoverflow.com/a/30189841/4351778 answer.
assistenzde/simple-cryptographic-bundle 适用场景与选型建议
assistenzde/simple-cryptographic-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cryptograhy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 assistenzde/simple-cryptographic-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 assistenzde/simple-cryptographic-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-01