Pix Lib and Validations #2
2 changed files with 26 additions and 15 deletions
23
src/Kore.php
23
src/Kore.php
|
@ -2,22 +2,34 @@
|
||||||
|
|
||||||
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'],
|
||||||
|
@ -26,5 +38,4 @@ class Kore
|
||||||
'delete' => curlRequest($this->url . '/delete', 'DELETE')['status']
|
'delete' => curlRequest($this->url . '/delete', 'DELETE')['status']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue