Identation and fixes to load keys
This commit is contained in:
parent
be5a68f217
commit
3472b19591
2 changed files with 26 additions and 15 deletions
37
src/Kore.php
37
src/Kore.php
|
@ -2,29 +2,40 @@
|
||||||
|
|
||||||
namespace Kontrl\PhpKore;
|
namespace Kontrl\PhpKore;
|
||||||
|
|
||||||
|
use phpseclib3\Common\Functions\Strings;
|
||||||
|
use phpseclib3\Crypt\EC;
|
||||||
|
use phpseclib3\Crypt\EC\PublicKey;
|
||||||
use phpseclib3\Crypt\PublicKeyLoader;
|
use phpseclib3\Crypt\PublicKeyLoader;
|
||||||
|
use phpseclib3\Crypt\RSA;
|
||||||
|
|
||||||
class Kore
|
class Kore
|
||||||
{
|
{
|
||||||
private $url = 'https://httpbin.org';
|
private $url = 'https://httpbin.org';
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct() {}
|
||||||
|
|
||||||
|
public function signBody($body, string|array $key, string|bool $password = false)
|
||||||
|
{
|
||||||
|
$privateKey = PublicKeyLoader::loadPrivateKey(base64_decode($key), $password);
|
||||||
|
$sig = $privateKey->sign($body);
|
||||||
|
$sig = base64_encode($sig);
|
||||||
|
return $sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function signBody(array $body, string|array $key, string|bool $password = false){
|
public function verifySignature($signature, $message, $key)
|
||||||
$publicKey = PublicKeyLoader::loadPrivateKey($key, $password);
|
{
|
||||||
return base64_encode($publicKey->sign(json_encode($body)));
|
$publicKey = PublicKeyLoader::loadPublicKey($key);
|
||||||
|
return $publicKey->verify($message, $signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRequest(){
|
public function testRequest()
|
||||||
|
{
|
||||||
return [
|
return [
|
||||||
'get' => curlRequest($this->url.'/get', 'GET')['status'],
|
'get' => curlRequest($this->url . '/get', 'GET')['status'],
|
||||||
'post' => curlRequest($this->url.'/post', 'POST', [], [], ['test' => 'test'])['status'],
|
'post' => curlRequest($this->url . '/post', 'POST', [], [], ['test' => 'test'])['status'],
|
||||||
'patch' => curlRequest($this->url.'/patch', 'PATCH', [], [], ['test' => 'test'])['status'],
|
'patch' => curlRequest($this->url . '/patch', 'PATCH', [], [], ['test' => 'test'])['status'],
|
||||||
'put' => curlRequest($this->url.'/put', 'PUT', [], [], ['test' => 'test'])['status'],
|
'put' => curlRequest($this->url . '/put', 'PUT', [], [], ['test' => 'test'])['status'],
|
||||||
'delete' => curlRequest($this->url.'/delete', 'DELETE')['status']
|
'delete' => curlRequest($this->url . '/delete', 'DELETE')['status']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ if (!function_exists('curlRequest')) {
|
||||||
if (!empty($queryParams)) {
|
if (!empty($queryParams)) {
|
||||||
$url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($queryParams);
|
$url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
CURLOPT_URL => $url,
|
CURLOPT_URL => $url,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
@ -29,7 +29,7 @@ if (!function_exists('curlRequest')) {
|
||||||
}
|
}
|
||||||
$options[CURLOPT_POSTFIELDS] = $body;
|
$options[CURLOPT_POSTFIELDS] = $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($headers)) {
|
if (!empty($headers)) {
|
||||||
$options[CURLOPT_HTTPHEADER] = $headers;
|
$options[CURLOPT_HTTPHEADER] = $headers;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue