init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\CafeBazaar;
|
||||
|
||||
class BazaarSignatureVerifier
|
||||
{
|
||||
public function verify(string $publicKey, string $originalJson, string $signature): bool
|
||||
{
|
||||
$pem = str_contains($publicKey, 'BEGIN PUBLIC KEY')
|
||||
? $publicKey
|
||||
: "-----BEGIN PUBLIC KEY-----\n".chunk_split(preg_replace('/\s+/', '', $publicKey) ?? '', 64, "\n")."-----END PUBLIC KEY-----\n";
|
||||
|
||||
$key = openssl_pkey_get_public($pem);
|
||||
$decodedSignature = base64_decode($signature, true);
|
||||
|
||||
if ($key === false || $decodedSignature === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return openssl_verify($originalJson, $decodedSignature, $key, OPENSSL_ALGO_SHA1) === 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user