1+ <?php
2+
3+ ////////////////////////////////////////////////////////////////////////////////
4+ //
5+ // StringEncrypt.com Web API usage example
6+ //
7+ // Version : v1.1
8+ // Language : PHP
9+ // Author : Bartosz Wójcik
10+ // Web page : https://www.stringencrypt.com
11+ //
12+ ////////////////////////////////////////////////////////////////////////////////
13+
14+ // include main library
15+ include ("stringencrypt.php " );
16+
17+ //
18+ // setup options
19+ //
20+ $ options = array ();
21+
22+ //
23+ // activation code, you can leave it empty for demo version, but keep in
24+ // mind that there are many limitations in demo version)
25+ //
26+ $ options ["code " ] = "" ;
27+
28+ //
29+ // API command to execute
30+ //
31+ // "encrypt" - encrypt input string or file bytes, returns array of:
32+ //
33+ // $result["error"] - error code
34+ // $result["source"] - decryptor source code
35+ // $result["expired"] - activation code expiration flag (bool)
36+ // $result["credits_left"] - number of credits left
37+ //
38+ // "is_demo" - checks current activation code and returns array of:
39+ //
40+ // $result["demo"] - demo mode flag (bool)
41+ // $result["label_limit"] - label limit length
42+ // $result["string_limit"] - string/file limit lenght
43+ // $result["credits_left"] - number of credits left
44+ // $result["cmd_min"] - minimum number of encryption commands
45+ // $result["cmd_max"] - maximum number of encryption commands
46+ $ options ["command " ] = "encrypt " ;
47+ //$options["command"] = "is_demo";
48+
49+ //
50+ // label name
51+ //
52+ // demo mode supports up to 6 chars only (64 in full version),
53+ // if you pass more than this number, service will return
54+ // ERROR_LENGTH_LABEL
55+ //
56+ $ options ["label " ] = "Label " ;
57+
58+ //
59+ // input string / raw bytes compression enabled, if you set it to
60+ // true, you need to compress input string / raw bytes eg.
61+ //
62+ // $compressed = @base64_encode(@gzcompress($string, 9)
63+ //
64+ // and after encryption you need to decompress encrypted data
65+ //
66+ // $decompressed = @gzuncompress(@base64_decode($source));
67+ //
68+ $ options ["compression " ] = false ;
69+ //$options["compression"] = true;
70+
71+ //
72+ // input string in UTF-8 format
73+ //
74+ // demo mode supports up to 6 chars only, if you pass more
75+ // than that, service will return ERROR_LENGTH_STRING
76+ //
77+ $ options ["string " ] = "Hello! " ;
78+ //$options["string"] = @base64_encode(@gzcompress("Hello!", 9));
79+
80+ //
81+ // raw data bytes to encrypt (you need to specify either
82+ // $options["string"] or this value
83+ //
84+ // demo mode doesn't support this parameter and the service
85+ // will return ERROR_DEMO
86+ //
87+ //$options["bytes"] = file_get_contents("my_file.txt");
88+ //$options["bytes"] = file_get_contents("http://www.example.com/my_file.txt");
89+ //$options["bytes"] = @base64_encode(@gzcompress(file_get_contents("my_file.txt"), 9));
90+
91+ //
92+ // treat input string as a UNICODE string (ANSI otherwise)
93+ //
94+ $ options ["unicode " ] = true ;
95+
96+ //
97+ // input string default locale (only those listed below
98+ // are supported currently)
99+ //
100+ $ options ["lang_locale " ] = "en_US.utf8 " ;
101+ //$options["lang_locale"] = "en_GB.utf8";
102+ //$options["lang_locale"] = "de_DE.utf8";
103+ //$options["lang_locale"] = "es_ES.utf8";
104+ //$options["lang_locale"] = "fr_BE.utf8";
105+ //$options["lang_locale"] = "fr_FR.utf8";
106+ //$options["lang_locale"] = "pl_PL.utf8";
107+
108+ //
109+ // how to encode new lines, available values:
110+ //
111+ // "lf" - Unix style
112+ // "crlf" - Windows style
113+ // "cr" - Mac style
114+ //
115+ $ options ["new_lines " ] = "lf " ;
116+ //$options["new_lines"] = "crlf";
117+ //$options["new_lines"] = "cr";
118+
119+ //
120+ // destination ANSI string encoding (if unicode = false)
121+ //
122+ // only those listed below are supported
123+ //
124+ $ options ["ansi_encoding " ] = "WINDOWS-1250 " ;
125+ //$options["ansi_encoding"] = "WINDOWS-1251";
126+ //$options["ansi_encoding"] = "WINDOWS-1252";
127+ //$options["ansi_encoding"] = "WINDOWS-1253";
128+ //$options["ansi_encoding"] = "WINDOWS-1254";
129+ //$options["ansi_encoding"] = "WINDOWS-1255";
130+ //$options["ansi_encoding"] = "WINDOWS-1256";
131+ //$options["ansi_encoding"] = "WINDOWS-1257";
132+ //$options["ansi_encoding"] = "WINDOWS-1258";
133+ //$options["ansi_encoding"] = "ISO-8859-1";
134+ //$options["ansi_encoding"] = "ISO-8859-2";
135+ //$options["ansi_encoding"] = "ISO-8859-3";
136+ //$options["ansi_encoding"] = "ISO-8859-9";
137+ //$options["ansi_encoding"] = "ISO-8859-10";
138+ //$options["ansi_encoding"] = "ISO-8859-14";
139+ //$options["ansi_encoding"] = "ISO-8859-15";
140+ //$options["ansi_encoding"] = "ISO-8859-16";
141+
142+ //
143+ // output programming language
144+ //
145+ // only those listed below are supported, if you pass
146+ // other name, service will return ERROR_INVALID_LANG
147+ //
148+ $ options ["lang " ] = "cpp " ;
149+ //$options["lang"] = "csharp";
150+ //$options["lang"] = "delphi";
151+ //$options["lang"] = "java";
152+ //$options["lang"] = "js";
153+ //$options["lang"] = "python";
154+ //$options["lang"] = "ruby";
155+ //$options["lang"] = "haskell";
156+ //$options["lang"] = "masm";
157+ //$options["lang"] = "fasm";
158+
159+ //
160+ // minimum number of encryption commands
161+ //
162+ // demo mode supports only up to 3 commands (50 in full version),
163+ // if you pass more than this number, service will return
164+ // ERROR_CMD_MIN
165+ //
166+ $ options ["cmd_min " ] = 1 ;
167+ //$options["cmd_min"] = 1;
168+
169+ //
170+ // maximum number of encryption commands
171+ //
172+ // demo mode supports only up to 3 commands (50 in full version),
173+ // if you pass more than this number, service will return
174+ // ERROR_CMD_MAX
175+ //
176+ $ options ["cmd_max " ] = 3 ;
177+ //$options["cmd_max"] = 50;
178+
179+ //
180+ // store encrypted string as a local variable (if supported
181+ // by the programming language), otherwise it's stored as
182+ // a global variable
183+ //
184+ $ options ["local " ] = false ;
185+ //$options["local"] = true;
186+
187+ //
188+ // encrypt string or file contents
189+ //
190+ $ result = stringencrypt ($ options );
191+
192+ if ($ result != false )
193+ {
194+ if ($ result ["error " ] == ERROR_SUCCESS )
195+ {
196+ // if compression was enabled, we need to
197+ // decompress the output source code
198+ if ($ options ["compression " ] == true )
199+ {
200+ $ source = @gzuncompress (@base64_decode ($ source ));
201+ }
202+ else
203+ {
204+ $ source = $ result ["source " ];
205+ }
206+
207+ // display decryptor body
208+ echo "<pre> " .$ source ."</pre> " ;
209+
210+ // display number of credits left
211+ echo "<p>You have {$ result ['credits_left ' ]} credits left.</p> " ;
212+
213+ // display initial number of credits
214+ echo "<p>Initial number of credits {$ result ['credits_total ' ]}.</p> " ;
215+
216+ // activation code has expired, notify user
217+ if ($ result ["expired " ] == true )
218+ {
219+ echo "<p>Your activation code has expired!</p> " ;
220+ }
221+ }
222+ else
223+ {
224+ echo "An error occured (code " .$ result ["error " ].") " ;
225+ }
226+ }
227+ else
228+ {
229+ echo "Cannot connect to the API interface! " ;
230+ }
231+
232+ ?>
0 commit comments