install phpseclib and create function to sign every body request

This commit is contained in:
Eduardo Bacarin 2025-06-13 16:25:04 -03:00
parent 37aab36cd9
commit be5a68f217
2 changed files with 9 additions and 5 deletions

View file

@ -16,5 +16,7 @@
"email": "me@bacarin.dev" "email": "me@bacarin.dev"
} }
], ],
"require": {} "require": {
"phpseclib/phpseclib": "~3.0"
}
} }

View file

@ -2,17 +2,19 @@
namespace Kontrl\PhpKore; namespace Kontrl\PhpKore;
use phpseclib3\Crypt\PublicKeyLoader;
class Kore class Kore
{ {
private $url = 'https://httpbin.org'; private $url = 'https://httpbin.org';
private $token;
public function __construct(){ public function __construct(){
$this->token = $this->auth();
} }
public function auth(){ public function signBody(array $body, string|array $key, string|bool $password = false){
return ''; $publicKey = PublicKeyLoader::loadPrivateKey($key, $password);
return base64_encode($publicKey->sign(json_encode($body)));
} }
public function testRequest(){ public function testRequest(){