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 our PHP example, first you have to setup configuration array $options = array();, specify API command to execute and call stringencrypt() function that will return $result array.

Currently we support only 2 commands:

  • Icon Lockencrypt - encrypt a string or file (raw bytes)
  • Icon Questionis_demo - returns information about current activation code status

"encrypt" command usage example

This example shows how to encrypt a string or file using our Web API interface.

<?php
 
////////////////////////////////////////////////////////////////////////////////
//
// StringEncrypt.com Web API usage example
//
// Version        : v1.1
// Language       : PHP
// Author         : Bartosz WĂłjcik
// Web page       : https://www.stringencrypt.com
//
////////////////////////////////////////////////////////////////////////////////
 
// include main library
include ("stringencrypt.php");
 
//
// setup options
//
$options = array();
 
//
// activation code, you can leave it empty for demo version, but keep in
// mind that there are many limitations in demo version)
//
$options["code"] = "";
 
//
// API command to execute
//
// "encrypt" - encrypt input string or file bytes, returns array of:
//
// $result["error"] - error code
// $result["source"] - decryptor source code
// $result["expired"] - activation code expiration flag (bool)
// $result["credits_left"] - number of credits left
//
// "is_demo" - checks current activation code and returns array of:
//
// $result["demo"] - demo mode flag (bool)
// $result["label_limit"] - label limit length
// $result["string_limit"] - string/file limit lenght
// $result["credits_left"] - number of credits left
// $result["cmd_min"] - minimum number of encryption commands
// $result["cmd_max"] - maximum number of encryption commands
$options["command"] = "encrypt";
//$options["command"] = "is_demo";
 
//
// label name
//
// demo mode supports up to 6 chars only (64 in full version),
// if you pass more than this number, service will return
// ERROR_LENGTH_LABEL
//
$options["label"] = "Label";
 
//
// input string / raw bytes compression enabled, if you set it to
// true, you need to compress input string / raw bytes eg.
//
// $compressed = @base64_encode(@gzcompress($string, 9)
//
// and after encryption you need to decompress encrypted data
//
// $decompressed = @gzuncompress(@base64_decode($source));
//
$options["compression"] = false;
//$options["compression"] = true;
 
//
// input string in UTF-8 format
//
// demo mode supports up to 6 chars only, if you pass more
// than that, service will return ERROR_LENGTH_STRING
//
$options["string"] = "Hello!";
//$options["string"] = @base64_encode(@gzcompress("Hello!", 9));
 
//
// raw data bytes to encrypt (you need to specify either
// $options["string"] or this value
//
// demo mode doesn't support this parameter and the service
// will return ERROR_DEMO
//
//$options["bytes"] = file_get_contents("my_file.txt");
//$options["bytes"] = file_get_contents("http://www.example.com/my_file.txt");
//$options["bytes"] = @base64_encode(@gzcompress(file_get_contents("my_file.txt"), 9));
 
//
// treat input string as a UNICODE string (ANSI otherwise)
//
$options["unicode"] = true;
 
//
// input string default locale (only those listed below
// are supported currently)
//
$options["lang_locale"] = "en_US.utf8";
//$options["lang_locale"] = "en_GB.utf8";
//$options["lang_locale"] = "de_DE.utf8";
//$options["lang_locale"] = "es_ES.utf8";
//$options["lang_locale"] = "fr_BE.utf8";
//$options["lang_locale"] = "fr_FR.utf8";
//$options["lang_locale"] = "pl_PL.utf8";
 
//
// how to encode new lines, available values:
//
// "lf" - Unix style
// "crlf" - Windows style
// "cr" - Mac style
//
$options["new_lines"] = "lf";
//$options["new_lines"] = "crlf";
//$options["new_lines"] = "cr";
 
//
// destination ANSI string encoding (if unicode = false)
//
// only those listed below are supported
//
$options["ansi_encoding"] = "WINDOWS-1250";
//$options["ansi_encoding"] = "WINDOWS-1251";
//$options["ansi_encoding"] = "WINDOWS-1252";
//$options["ansi_encoding"] = "WINDOWS-1253";
//$options["ansi_encoding"] = "WINDOWS-1254";
//$options["ansi_encoding"] = "WINDOWS-1255";
//$options["ansi_encoding"] = "WINDOWS-1256";
//$options["ansi_encoding"] = "WINDOWS-1257";
//$options["ansi_encoding"] = "WINDOWS-1258";
//$options["ansi_encoding"] = "ISO-8859-1";
//$options["ansi_encoding"] = "ISO-8859-2";
//$options["ansi_encoding"] = "ISO-8859-3";
//$options["ansi_encoding"] = "ISO-8859-9";
//$options["ansi_encoding"] = "ISO-8859-10";
//$options["ansi_encoding"] = "ISO-8859-14";
//$options["ansi_encoding"] = "ISO-8859-15";
//$options["ansi_encoding"] = "ISO-8859-16";
 
//
// output programming language
//
// only those listed below are supported, if you pass
// other name, service will return ERROR_INVALID_LANG
//
$options["lang"] = "cpp";
//$options["lang"] = "csharp";
//$options["lang"] = "delphi";
//$options["lang"] = "java";
//$options["lang"] = "js";
//$options["lang"] = "python";
//$options["lang"] = "ruby";
//$options["lang"] = "autoit";
//$options["lang"] = "haskell";
//$options["lang"] = "masm";
//$options["lang"] = "fasm";
 
//
// minimum number of encryption commands
//
// demo mode supports only up to 3 commands (50 in full version),
// if you pass more than this number, service will return
// ERROR_CMD_MIN
//
$options["cmd_min"] = 1;
//$options["cmd_min"] = 1;
 
//
// maximum number of encryption commands
//
// demo mode supports only up to 3 commands (50 in full version),
// if you pass more than this number, service will return
// ERROR_CMD_MAX
//
$options["cmd_max"] = 3;
//$options["cmd_max"] = 50;
 
//
// store encrypted string as a local variable (if supported
// by the programming language), otherwise it's stored as
// a global variable
//
$options["local"] = false;
//$options["local"] = true;
 
//
// encrypt string or file contents
//
$result = stringencrypt($options);
 
if ($result != false)
{
	if ($result["error"] == ERROR_SUCCESS)
	{
		// if compression was enabled, we need to
		// decompress the output source code
		if ($options["compression"] == true)
		{
			$source = @gzuncompress(@base64_decode($source));
		}
		else
		{
			$source = $result["source"];
		}
 
		// display decryptor body
		echo "<pre>".$source."</pre>";
 
		// display number of credits left
		echo "<p>You have {$result['credits_left']} credits left.</p>";
 
		// display initial number of credits
		echo "<p>Initial number of credits {$result['credits_total']}.</p>";
 
		// activation code has expired, notify user
		if ($result["expired"] == true)
		{
			echo "<p>Your activation code has expired!</p>";
		}
	}
	else
	{
		echo "An error occured (code ".$result["error"].")";
	}
}
else
{
	echo "Cannot connect to the API interface!";
}
?>

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:

  • Icon Tick GreenERROR_SUCCESS (0) - everything went fine
  • Icon Tick RedERROR_EMPTY_LABEL (1) - label parameter is empty
  • Icon Tick RedERROR_LENGTH_LABEL (2) - label length is too long
  • Icon Tick RedERROR_EMPTY_STRING (3) - input string is empty
  • Icon Tick RedERROR_EMPTY_BYTES (4) - input file bytes array is empty
  • Icon Tick RedERROR_EMPTY_INPUT (5) - input source (either string or file) is missing
  • Icon Tick RedERROR_LENGTH_STRING (6) - string or bytes length is too long
  • Icon Tick RedERROR_INVALID_LANG (7) - programming language not supported
  • Icon Tick RedERROR_INVALID_LOCALE (8) - language locale is not supported
  • Icon Tick RedERROR_CMD_MIN (9) - invalid number of minimum encryption commands
  • Icon Tick RedERROR_CMD_MAX (10) - invalid number of maximum encryption commands
  • Icon Tick RedERROR_DEMO (100) - you need a valid code to use full version features

"is_demo" command usage example

This example shows how to get information about current activation code and its features.

<?php
 
////////////////////////////////////////////////////////////////////////////////
//
// StringEncrypt.com Web API usage example
//
// Version        : v1.1
// Language       : PHP
// Author         : Bartosz WĂłjcik
// Web page       : https://www.stringencrypt.com
//
////////////////////////////////////////////////////////////////////////////////
 
// include main library
include ("stringencrypt.php");
 
//
// setup options
//
$options = array();
 
//
// activation code, you can leave it empty for demo version, but keep in
// mind that in demo versions there are many limitations)
//
$options["code"] = "";
 
//
// API command to execute
//
// "encrypt" - encrypt input string or file bytes, returns array of:
//
// $result["error"] - error code
// $result["source"] - decryptor source code
// $result["expired"] - activation code expiration flag (bool)
// $result["credits_left"] - number of credits left
//
// "is_demo" - checks current activation code and returns array of:
//
// $result["demo"] - demo mode flag (bool)
// $result["label_limit"] - label limit length
// $result["string_limit"] - string/file limit lenght
// $result["credits_left"] - number of credits left
// $result["cmd_min"] - minimum number of encryption commands
// $result["cmd_max"] - maximum number of encryption commands
//$options["command"] = "encrypt";
$options["command"] = "is_demo";
 
//
// execute API command
//
$result = stringencrypt($options);
 
if ($result != false)
{
	if ($result["demo"] == true)
	{
		echo "<p>You are running in DEMO mode</p>";
	}
	else
	{
		echo "<p>You are running in FULL mode</p>";
 
		// display number of credits left
		echo "<p>You have {$result['credits_left']} credits left.</p>";
 
		// display initial number of credits
		echo "<p>Initial number of credits {$result['credits_total']}.</p>";
	}
 
	echo "<p>Label max. length {$result['label_limit']} characters</p>";
 
	echo "<p>String/file max. length {$result['string_limit']} characters</p>";
 
	echo "<p>Minimum number of encryption commands {$result['cmd_min']}</p>";
	echo "<p>Maximum number of encryption commands {$result['cmd_max']}</p>";
}
else
{
	echo "Cannot connect to the API interface!";
}
?>

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/file limit lenght
  • 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