PHP code example of javascriptobfuscator / jso-protector
1. Go to this page and download the library: Download javascriptobfuscator/jso-protector library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
javascriptobfuscator / jso-protector example snippets
$client = new \JsoProtector\Client();
$result = $client->protect([
'files' => ['app.js' => file_get_contents('dist/app.js')],
'preset' => 'balanced',
'label' => getenv('GIT_COMMIT') ?: null,
// apiKey/apiPassword default to JSO_API_KEY / JSO_API_PASSWORD env vars.
]);
foreach ($result->files as $name => $code) {
file_put_contents("dist-protected/$name", $code);
}
echo "BuildId: {$result->buildId}\n";
echo "Fingerprint: {$result->polymorphismFingerprint}\n";
// app/Console/Commands/ProtectJs.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use JsoProtector\Client;
use JsoProtector\Exception as JsoException;
class ProtectJs extends Command
{
protected $signature = 'js:protect {input} {output} {--preset=balanced}';
public function handle(): int
{
try {
$result = (new Client())->protect([
'files' => ['app.js' => file_get_contents($this->argument('input'))],
'preset' => $this->option('preset'),
'label' => trim((string)exec('git rev-parse HEAD')),
]);
file_put_contents($this->argument('output'), $result->files['app.js']);
$this->info("Protected. BuildId={$result->buildId} fp={$result->polymorphismFingerprint}");
return self::SUCCESS;
} catch (JsoException $e) {
$this->error("JSO failed: {$e->getMessage()} (type={$e->type})");
return self::FAILURE;
}
}
}
$client = new \JsoProtector\Client(function (string $endpoint, string $body): array {
return ['status' => 200, 'body' => '{"Type":"Succeed","Items":[...]}'];
});