API

API Interface

You can use all of the features of StringEncrypt via our Web API interface.

Our API is based on POST requests and JSON encoded response.

In PHP, call the API with the pelock/stringencrypt package: configure a StringEncrypt\Client with setters, then call send() to get the same JSON-shaped array as the web form.

Commands (POST field command / StringEncrypt\Command):

  • Icon Lockencrypt — encrypt a UTF-8 string or raw bytes (file); returns decryptor source
  • Icon Questionis_demo — activation limits, demo vs full mode, credits
  • Icon Infoinfo — engine version and supported output languages

"encrypt" command usage example

Official PHP client (examples/encrypt.php). setApiKey('') is the activation code (empty = demo). With setCompression(true), the client decompresses source in the returned array by default. Use setBytes() instead of setString() for raw file bytes (full license).

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use StringEncrypt\Client;
use StringEncrypt\Command;
use StringEncrypt\ErrorCode;
use StringEncrypt\Language;
use StringEncrypt\NewLine;

$client = new Client();
$client
    ->setCommand(Command::Encrypt)
    ->setApiKey('')
    ->setLabel('Label')
    ->setCompression(false)
    ->setString('Hello!')
    ->setUnicode(true)
    ->setLangLocale('en_US.utf8')
    ->setNewLines(NewLine::Lf)
    ->setAnsiEncoding('WINDOWS-1250')
    ->setLanguage(Language::Cpp)
    ->setCmdMin(1)
    ->setCmdMax(3)
    ->setLocal(false);

$result = $client->send();

if ($result === false) {
    echo "Cannot connect to the API.\n";
    exit(1);
}

if (($result['error'] ?? null) !== ErrorCode::SUCCESS) {
    echo 'API error: ' . (string) ($result['error'] ?? 'unknown') . "\n";
    exit(1);
}

echo (string) $result['source'] . "\n";

Return values:

  • Icon Value$result["error"] (int) - error code
  • Icon Value$result["source"] (string) - decryptor source code
  • Icon Value$result["expired"] (boolean) - expiration flag
  • Icon Value$result["credits_left"] (int) - number of credits left
  • Icon Value$result["credits_total"] (int) - initial number of credits

Error codes (compare $result['error'] to StringEncrypt\ErrorCode::*):

  • Icon Tick GreenSUCCESS (0) - everything went fine
  • Icon Tick RedEMPTY_LABEL (1) - label parameter is empty
  • Icon Tick RedLENGTH_LABEL (2) - label length is too long
  • Icon Tick RedEMPTY_STRING (3) - input string is empty
  • Icon Tick RedEMPTY_BYTES (4) - input file bytes array is empty
  • Icon Tick RedEMPTY_INPUT (5) - input source (either string or file) is missing
  • Icon Tick RedLENGTH_STRING (6) - string length is too long
  • Icon Tick RedLENGTH_BYTES (11) - bytes length is too long
  • Icon Tick RedINVALID_LANG (7) - programming language not supported
  • Icon Tick RedINVALID_LOCALE (8) - language locale is not supported
  • Icon Tick RedCMD_MIN (9) - invalid number of minimum encryption commands
  • Icon Tick RedCMD_MAX (10) - invalid number of maximum encryption commands
  • Icon Tick RedDEMO (100) - you need a valid code to use full version features

"info" command usage example

Returns engine version and the list of supported lang values (see examples/info.php).

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use StringEncrypt\Client;
use StringEncrypt\Command;

$client = new Client();
$client
    ->setCommand(Command::Info)
    ->setApiKey('');

$result = $client->send();

if ($result === false || !isset($result['engine_version'])) {
    echo "Cannot connect to the API.\n";
    exit(1);
}

echo 'Engine: ' . $result['engine_version'] . "\n";
print_r($result['supported_languages'] ?? []);

"is_demo" command usage example

Query demo vs full limits for the current activation code (examples/is_demo.php).

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

use StringEncrypt\Client;
use StringEncrypt\Command;

$client = new Client();
$client
    ->setCommand(Command::IsDemo)
    ->setApiKey('');

$result = $client->send();

if ($result === false) {
    echo "Cannot connect to the API.\n";
    exit(1);
}

if (!empty($result['demo'])) {
    echo "DEMO mode\n";
} else {
    echo "FULL mode\n";
    echo 'Credits left: ' . (string) ($result['credits_left'] ?? '') . "\n";
}

echo 'Label max length: ' . (string) ($result['label_limit'] ?? '') . "\n";
echo 'String max length: ' . (string) ($result['string_limit'] ?? '') . "\n";
echo 'Bytes max length: ' . (string) ($result['bytes_limit'] ?? '') . "\n";
echo 'cmd_min / cmd_max: ' . (string) ($result['cmd_min'] ?? '') . ' / ' . (string) ($result['cmd_max'] ?? '') . "\n";

Return values:

  • Icon Value$result["demo"] (boolean) - demo mode flag
  • Icon Value$result["label_limit"] (int) - label limit length
  • Icon Value$result["string_limit"] (int) - string limit length
  • Icon Value$result["bytes_limit"] (int) - bytes/file limit length
  • Icon Value$result["credits_left"] (int) - number of credits left
  • Icon Value$result["credits_total"] (int) - initial number of credits
  • Icon Value$result["cmd_min"] (int) - minimum number of encryption commands
  • Icon Value$result["cmd_max"] (int) - maximum number of encryption commands

Error codes: none