protected function verifySignatureWithCertificate($certPath, $data, $signature)
    {
        $file = @fopen($certPath, "r");
        if ($file === false) {
            throw new Exception('Could not open certificate file. ');
        }
        $fileSize = filesize($certPath);

        $certificate = fread($file, $fileSize);
        fclose($file);

        $publicKey = openssl_pkey_get_public($certificate);

        $isVerified = openssl_verify($data, $signature, $publicKey);
        openssl_free_key($publicKey);

        if ($isVerified === 0) {
            throw new Exception('Incorrect signature');
        } elseif ($isVerified === -1) {
            throw new Exception('Could not verify signature');
        }

        return $isVerified;
    }