symflex / openssl-component
OpenSSL 组件
dev-master
2020-07-28 13:33 UTC
Requires
- php: ^7.4
- ext-openssl: *
Requires (Dev)
- phpunit/phpunit: ^8.5.1
This package is auto-updated.
Last update: 2024-09-29 00:46:14 UTC
README
安装
此包在 Packagist 上可用,您可以使用 Composer 安装它。
composer require symflex/openssl-component
依赖关系
- PHP 7.4
- OpenSSL 扩展
用法
use Symflex\Component\OpenSSL\Key\PemPublicKey; use Symflex\Component\OpenSSL\Key\PemPrivateKey; ... $publicKey = new PemPublicKey('file:///path_to_file'); $privateKey = new PemPrivateKey('file:///path_to_file', 'passphrase');
或
use Symflex\Component\OpenSSL\Factory\Key\PemKeyFactory; ... $keyFactory = new \Symflex\Component\OpenSSL\Factory\Key\PemKeyFactory(); $publicKey = $keyFactory->createPublicKey('file:///path_to_file'); $privateKey = $keyFactory->createPrivateKey('file:///path_to_file', 'passphrase');
use Symflex\Component\OpenSSL\Signature\Algorithm\Rsa\Sha256; $data = 'test string'; $opensslSigner = new Sha256($publicKey, $privateKey); $signature = $opensslSigner->sign($data); $opensslSigner->verify($data, $signature);