francodacosta / caparica
使用签名请求确保您的REST API安全
1.0
2014-10-04 12:34 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- evert/phpdoc-md: ~0.0.7
- phpdocumentor/phpdocumentor: 2.*
Suggests
- doctrine/orm: to use the DOCTRINE client provider
- symfony/yaml: to use the YAML client provider
README
PHP库,用于验证和创建签名请求
这是一个低级别库,你可能需要查看
- Caparica Bundle,一个 symfony2 扩展包
- Caparica Guzzle,一个自动为你的请求签名的 Guzzle 插件
安装
composer.phar require francodacosta/caparica
文档
请务必阅读文档,确保您理解 Caparica 的客户端和服务器部分。
最新文档可以在 docs 文件夹 中找到
签名请求 (客户端)
use Caparica\Crypto\RequestSigner; $signer = new RequestSigner(); $password = "12345678901234567890"; $params = array ( 'a' => 'bcd', 'c' => '123', 'b' => 'ewq', 'X-CAPARICA-TIMESTAMP' => date('U') ); $signature = $signer->sign($params, $password);
验证请求 (服务器端)
use Caparica\Security\RequestValidator; use Caparica\Client\BasicClient; $client = new BasicClient; $requestValidator = new RequestValidator(new RequestSigner); // this values come from the request the client made // use whatever methods your framework has to access http requests $requestParams = array( 'X-CAPARICA-DATE' => "12345676743", 'a' => 'bcd', 'c' => '123', 'b' => 'ewq', ); // the signature comes from the request, we will use it to compare with the server // generated one, if they match we know the request is valid $requestSignature = '0c6513e432bb25d8be659a99ca240a64f60dee875e04d557341a677bfe08a1bf'; $isValid = $requestValidator->validate($client, $requestSignature, $requestParams);