b3da / eos-bundle
Symfony 组件,用于简化 OpenSSL 操作
dev-master
2016-06-11 16:17 UTC
Requires
- php: >=5.5.9
- symfony/framework-bundle: ~2.8|~3.1
This package is not auto-updated.
Last update: 2024-09-14 19:20:06 UTC
README
Symfony 组件,用于简化 OpenSSL 加密、解密和密钥对生成。
依赖关系
- symfony/framework-standard-edition ">=2.8|~3.1"
安装
-
使用 Symfony 框架创建项目
-
composer require b3da/eos-bundle "dev-master"
-
AppKernel.php
new b3da\EasyOpenSslBundle\b3daEasyOpenSslBundle(),
parameters.yml(.dist)
# EasyOpenSSL encryption method eos_enc_method: aes-256-cbc # ...
-
(您可以从
b3da\EasyOpenSslBundle
命名空间扩展Client
和Message
实体) -
更新您的模式
使用方法
- new 服务
b3da_easy_open_ssl.eos
可用于 OpenSSL 操作
$eos = $this->get('b3da_easy_open_ssl.eos');
- 创建 Client 示例 (
FooController
)
$client = new Client(); $client = $eos->generateKeyPairForClient($client); if (!$client) { // err generating keypair } // persist Client with keys
- 通过 Client 的私钥加密数据的示例 (
FooController
)
$message = $eos->encrypt($client, 'msg data .. foo bar baz');
- 通过 Client 的公钥解密数据的示例 (
FooController
)
$decryptedData = $eos->decrypt($message); // $decryptedData === 'msg data .. foo bar baz';
简单的 API 用于基本任务(可选)
- 将路由导入
routing.yml
b3da_easy_open_ssl: resource: "@b3daEasyOpenSslBundle/Controller/" type: annotation prefix: /eos/
- /eos/msg-api/client/create/ [POST]
Response: {"status":"success","id":"3ead5521-2fbc-11e6-834a-f0def1ff5901"} or {"status":"error","details":"key pair generating failed"}
- /eos/msg-api/client/export-public/{id}/ [GET]
Response: {"status":"success","data":{"id":"3ead5521-2fbc-11e6-834a-f0def1ff5901","pubkey":"LS0tLS1CR .. S0tLQ=="}} or {"status":"error","details":"no client for id"}
- /eos/msg-api/client/import-public/{id}/ [POST]
Request: {"data":{"id":"3ead5521-2fbc-11e6-834a-f0def1ff5901","pubkey":"LS0tLS1CR .. S0tLQ=="}} Response: {"status":"success","id":"3ead5521-2fbc-11e6-834a-f0def1ff5901"} or {"status":"error","details":"no data to import"}
- /eos/msg-api/msg/encrypt/{clientId}/{data}/ [GET]
Response: {"status":"success","data":{"message":":774c6b663650636 .. 34346616f5901"}} or {"status":"error","details":"no client for id"}
- /eos/msg-api/msg/decrypt/{data}/ [GET]
Request: /eos/msg-api/msg/decrypt/{"message":":774c6b663650636 .. 34346616f5901"}/ Response: {"status":"success","data":"foo bar"} or {"status":"error","details":"wrong format"}