Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
307 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
 
25
#使用命名空間qbpwcf
26
namespace qbpwcf;
27
 
28
#取得 lib path
29
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
30
 
31
#如果執行失敗
32
if($status!==0){
33
 
34
	#debug
35
	var_dump(__LINE__,$output);
36
 
37
	#結束執行,回傳shell 1.
38
	exit(1);
39
 
40
	}#if end
41
 
42
#儲存lib path
43
$folderOfUsrLib=$output[0];
44
 
45
#以該檔案的實際位置的 lib path 為 include path 首位
46
$output=array();
47
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
48
 
49
#如果執行失敗
50
if($status!==0){
51
 
52
	#debug
53
	var_dump(__LINE__,$output);
54
 
55
	#結束執行,回傳shell 1.
56
	exit(1);
57
 
58
	}#if end
59
 
60
#設置 include path
61
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
62
 
63
#匯入外部套件
64
require_once("allInOne.php");
65
 
66
#該指令的 help 文件
67
function help(){
68
 
69
	#印出指令說明
70
	echo basename($_SERVER["PHP_SELF"])." is a program to encrypt string or stdin by gpg then stdout.".PHP_EOL;
71
	echo basename($_SERVER["PHP_SELF"])." usage:".PHP_EOL;
72
	echo "--input [string to encrypt]".PHP_EOL;
73
	echo "--outputHexWhenEncrypt [on/off] deafult is \"on\"".PHP_EOL;
74
	echo "\t\"on\" means format of stdout will be ascii;\"false\" means format of stdout will be binary.".PHP_EOL;
75
	echo "stdin example:".PHP_EOL;
76
	echo "\techo \"password to encrypt\" | ".basename($_SERVER["PHP_SELF"]).PHP_EOL;
77
	echo "--decrypt [on/off] defalult if \"off\".".PHP_EOL;
78
	echo "\t\"on\" means decrypt input;\"false\" means encrypt input.".PHP_EOL;
79
	echo "--hex2binFirstWhenDecrypt [on/off] default if on when decrypt is on.".PHP_EOL; 
80
	echo "\t\"on\" means order of decrypt process is hex2bin first then gpg gpe decrypt;\"off\" meams gpg decrypt directly.".PHP_EOL;
81
	echo "chooseIdByEmail [email for gpg id] default is gnupgId from config file etc/qbpwcf/allInOneConfig.php".PHP_EOL;
82
 
83
	#結束執行
84
	exit;
85
 
86
	}#function help end
87
 
88
#函式說明:
89
#解析參數.
90
#回傳結果:
91
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
92
#$reuslt["error"],執行不正常結束的錯訊息陣列.
93
#$result["function"],當前執行的函式名稱.
94
#$result["content"],解析好的參數陣列.
95
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
96
#$result["program"],字串,執行的程式名稱.
97
#必填參數:
98
#無
99
#可省略參數:
100
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
101
$conf["helpFunc"]="help";
102
#備註:
103
#僅能在命令列底下執行.
104
#建議:
105
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
106
$parseArgu=cmd::parseArgu($conf);
107
unset($conf);
108
 
109
#如果解析參數失敗
110
if($parseArgu["status"]==="false"){
111
 
112
	#印出結果
113
	var_dump($parseArgu);
114
 
115
	#結束執行,回傳 shell 1
116
	exit(1);
117
 
118
	}#if end
119
 
120
#函式說明:
121
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
122
#回傳結果:
123
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
124
#$result["error"],執行不正常結束的錯訊息陣列.
125
#$result["simpleError"],簡單表示的錯誤訊息.
126
#$result["function"],當前執行的函式名稱.
127
#$result["argu"],設置給予的參數.
128
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
129
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
130
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
131
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
132
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
133
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
134
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
135
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
136
#必填參數:
137
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
138
$conf["varInput"]=&$parseArgu["content"];
139
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
140
$conf["referenceVarKey"]="variableCheck::checkArguments";
141
#可省略參數:
142
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
143
#$conf["mustBeFilledVariableName"]=array();
144
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
145
#$conf["mustBeFilledVariableType"]=array();
146
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
147
#$conf["canBeEmptyString"]="false";
148
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
149
#$conf["canNotBeEmpty"]=array();
150
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
151
#$conf["canBeEmpty"]=array();
152
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
153
#$conf["skipableVariableCanNotBeEmpty"]=array();
154
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
155
$conf["skipableVariableName"]=array("input","outputHexWhenEncrypt","decrypt","hex2binFirstWhenDecrypt","chooseIdByEmail");
156
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
157
$conf["skipableVariableType"]=array("array","array","array","array","array");
158
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
159
$conf["skipableVarDefaultValue"]=array(null,array("on"),array("off"),null,array(gnupgId));
160
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
161
#$conf["disallowAllSkipableVarIsEmpty"]="";
162
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
163
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
164
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
165
#$conf["disallowAllSkipableVarNotExist"]="";
166
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
167
#$conf["arrayCountEqualCheck"][]=array();
168
#參考資料:
169
#array_keys=>http://php.net/manual/en/function.array-keys.php
170
#備註:
171
#無.
172
$checkArguments=variableCheck::checkArguments($conf);
173
unset($conf);
174
 
175
#如果執行異常
176
if($checkArguments["status"]==="false"){
177
 
178
	#debug
179
	var_dump($checkArguments);
180
 
181
	#結束執行,回傳 shell 1
182
	exit(1);
183
 
184
	}#if end
185
 
186
#如果執行異常
187
if($checkArguments["passed"]==="false"){
188
 
189
	#debug
190
	var_dump($checkArguments);
191
 
192
	#結束執行,回傳 shell 1
193
	exit(1);
194
 
195
	}#if end
196
 
197
#取得 outputHexWhenEncrypt 參數的內容
198
$outputHexWhenEncrypt=$parseArgu["content"]["outputHexWhenEncrypt"][0];
199
 
200
#取得 decrypt 參數的內容
201
$decrypt=$parseArgu["content"]["decrypt"][0];
202
 
203
#取得 chooseIdByEmail 參數的內容
204
$chooseIdByEmail=$parseArgu["content"]["chooseIdByEmail"][0];
205
 
206
#如果有 input 參數
207
if(isset($parseArgu["content"]["input"])){
208
 
209
	#取得輸入的 input 參數數值
210
	$input=$parseArgu["content"]["input"][0];
211
 
212
	}#if end
213
 
214
#反之
215
else{
216
 
217
	#讀取 stdin - start
218
 
219
	#讀取不定長度的資源
220
	#參考資料:
221
	#https://www.php.net/manual/en/function.fread.php
222
 
223
	#初始化標準輸入的內容
224
	$stdin="";
225
 
226
	#如果有標準輸入的內容
227
	while(!FEOF(STDIN)){
228
 
229
		#串接讀取的標準輸入
230
		$stdin=$stdin.fread(STDIN,8192);
231
 
232
		}#while end
233
 
234
	#如果有標準輸入
235
	if(!empty($stdin)){
236
 
237
		#取得其參考
238
		$input=&$stdin;
239
 
240
		/*
241
 
242
		#透過 stdin 結尾會多一個 byte(用於識別FEOF)
243
 
244
		#函式說明:
245
		#移除字串結尾的1byte
246
		#回傳結果:
247
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
248
		#$result["error"],錯誤訊息陣列.
249
		#$result["function"],當前執行的函數名稱.
250
		#$result["content"],處理好的字串
251
		#必填參數:
252
		#$conf["str"],字串",要處理的字串
253
		$conf["stringProcess::delLastByte"]["str"]=$input;
254
		#可省略參數:
255
		#無.
256
		#參考資料:
257
		#無.
258
		#備註:
259
		#無.
260
		$delLastByte=stringProcess::delLastByte($conf["stringProcess::delLastByte"]);
261
		unset($conf["stringProcess::delLastByte"]);
262
 
263
		#如果執行異常
264
		if($delLastByte["status"]==="false"){
265
 
266
			#印出結果
267
			var_dump($delLastByte);
268
 
269
			#結束執行,回傳 shell 1
270
			exit(1);
271
 
272
			}#if end
273
 
274
		#取得處理好的字串結果
275
		$input=$delLastByte["content"];
276
 
277
		*/
278
 
279
		}#if end
280
 
281
	#讀取 stdin - end
282
 
283
	}#else 
284
 
285
#如果是要 decrypt
286
if($decrypt==="on"){
287
 
288
	#如果沒有指定參數 hex2binFirstWhenDecrypt
289
	if(!isset($parseArgu["content"]["hex2binFirstWhenDecrypt"])){
290
 
291
		#設置為 "on"
292
		$hex2binFirstWhenDecrypt="on";
293
 
294
		}#if end
295
 
296
	#反之
297
	else{
298
 
299
		#取得參數 hex2binFirstWhenDecrypt 的數值
300
		$hex2binFirstWhenDecrypt=$parseArgu["content"]["hex2binFirstWhenDecrypt"][0];
301
 
302
		}#else end
303
 
304
	# hex to bin then gpg decrypt
305
	if($hex2binFirstWhenDecrypt==="on"){
306
 
307
		#函式說明:
308
		#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
309
		#回傳結果:
310
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
311
		#$result["function"],當前執行的函數名稱.
312
		#$result["content"],加密後的結果.
313
		#$result["error"],錯誤訊息陣列.
314
		#$result["argu"],使用的參數.
315
		#必填參數:
316
		#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
317
		$conf["enCodeStr"]=$input;
318
		#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
319
		$conf["enCodeType"]="hex2bin";
320
		#可省略參數:
321
		#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
322
		#$conf["sha1Raw"]="false";
323
		#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
324
		#$conf["p_hash"]="";
325
		#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
326
		#$conf["keyForAes256"]="";
327
		#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
328
		#$conf["aes256Encode"]="";
329
		#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
330
		#$conf["qbpwcfDecode"]="false";
331
		#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
332
		#$conf["gpgDecrypt"]="true";
333
		#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
334
		#$conf["gpgId"]=$chooseIdByEmail;
335
		#參考資料:
336
		#sha1=>http://php.net/manual/en/function.sha1.php
337
		#md5=>http://php.net/manual/en/function.md5.php
338
		#password_hash=>http://php.net/manual/en/function.password-hash.php
339
		#password_verify=>http://php.net/manual/en/function.password-verify.php
340
		#json_decode=>https://www.php.net/manual/en/function.json-decode.php
341
		#備註:
342
		#無.
343
		$enCodeStr=authenticate::enCodeStr($conf);
344
		unset($conf);
345
 
346
		#如果執行異常
347
		if($enCodeStr["status"]==="false"){
348
 
349
			#印出結果
350
			var_dump($enCodeStr);
351
 
352
			#結束執行,回傳 shell 1
353
			exit(1);
354
 
355
			}#if end
356
 
357
		#取得結果
358
		$input=$enCodeStr["content"];
359
 
360
		#var_dump($input);exit;
361
 
362
		}#if end
363
 
364
	#函式說明:
365
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
366
	#回傳結果:
367
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
368
	#$result["function"],當前執行的函數名稱.
369
	#$result["content"],加密後的結果.
370
	#$result["error"],錯誤訊息陣列.
371
	#$result["argu"],使用的參數.
372
	#必填參數:
373
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
374
	$conf["enCodeStr"]=$input;
375
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
376
	$conf["enCodeType"]="gpg";
377
	#可省略參數:
378
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
379
	#$conf["sha1Raw"]="false";
380
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
381
	#$conf["p_hash"]="";
382
	#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
383
	#$conf["keyForAes256"]="";
384
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
385
	#$conf["aes256Encode"]="";
386
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
387
	#$conf["qbpwcfDecode"]="false";
388
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
389
	$conf["gpgDecrypt"]="true";
390
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
391
	$conf["gpgId"]=$chooseIdByEmail;
392
	#參考資料:
393
	#sha1=>http://php.net/manual/en/function.sha1.php
394
	#md5=>http://php.net/manual/en/function.md5.php
395
	#password_hash=>http://php.net/manual/en/function.password-hash.php
396
	#password_verify=>http://php.net/manual/en/function.password-verify.php
397
	#json_decode=>https://www.php.net/manual/en/function.json-decode.php
398
	#備註:
399
	#無.
400
	$enCodeStr=authenticate::enCodeStr($conf);
401
	unset($conf);
402
 
403
	#var_dump($enCodeStr);
404
 
405
	#如果執行異常
406
	if($enCodeStr["status"]==="false"){
407
 
408
		#印出結果
409
		var_dump($enCodeStr);
410
 
411
		#結束執行,回傳 shell 1
412
		exit(1);
413
 
414
		}#if end
415
 
416
	#取得解密後的結果
417
	$input=$enCodeStr["content"];
418
 
419
	}#if end
420
 
421
#反之如果是要 encrypt
422
else if($decrypt==="off"){
423
 
424
	#函式說明:
425
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
426
	#回傳結果:
427
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
428
	#$result["function"],當前執行的函數名稱.
429
	#$result["content"],加密後的結果.
430
	#$result["error"],錯誤訊息陣列.
431
	#$result["argu"],使用的參數.
432
	#必填參數:
433
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
434
	$conf["enCodeStr"]=$input;
435
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
436
	$conf["enCodeType"]="gpg";
437
	#可省略參數:
438
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
439
	#$conf["sha1Raw"]="false";
440
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
441
	#$conf["p_hash"]="";
442
	#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
443
	#$conf["keyForAes256"]="";
444
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
445
	#$conf["aes256Encode"]="";
446
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
447
	#$conf["qbpwcfDecode"]="false";
448
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
449
	$conf["gpgDecrypt"]="false";
450
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
451
	$conf["gpgId"]=$chooseIdByEmail;
452
	#參考資料:
453
	#sha1=>http://php.net/manual/en/function.sha1.php
454
	#md5=>http://php.net/manual/en/function.md5.php
455
	#password_hash=>http://php.net/manual/en/function.password-hash.php
456
	#password_verify=>http://php.net/manual/en/function.password-verify.php
457
	#json_decode=>https://www.php.net/manual/en/function.json-decode.php
458
	#備註:
459
	#無.
460
	$enCodeStr=authenticate::enCodeStr($conf);
461
	unset($conf);
462
 
463
	#如果執行異常
464
	if($enCodeStr["status"]==="false"){
465
 
466
		#印出結果
467
		var_dump($enCodeStr);
468
 
469
		#結束執行,回傳 shell 1
470
		exit(1);
471
 
472
		}#if end
473
 
474
	#取得加密後的內容
475
	$input=$enCodeStr["content"];
476
 
477
	}#if end
478
 
479
#參數 decrypt 的內容異常 
480
else{
481
 
482
	#顯示help
483
	help();
484
 
485
	#結束運行
486
	exit;
487
 
488
	}#else end
489
 
490
#如果要輸出 hex 格式的內容 且為解密
491
if($outputHexWhenEncrypt==="on" && $decrypt==="off"){
492
 
493
	#函式說明:
494
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
495
	#回傳結果:
496
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
497
	#$result["function"],當前執行的函數名稱.
498
	#$result["content"],加密後的結果.
499
	#$result["error"],錯誤訊息陣列.
500
	#$result["argu"],使用的參數.
501
	#必填參數:
502
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
503
	$conf["enCodeStr"]=$input;
504
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過json_encode、urlencode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
505
	$conf["enCodeType"]="bin2hex";
506
	#可省略參數:
507
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
508
	#$conf["sha1Raw"]="false";
509
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
510
	#$conf["p_hash"]="";
511
	#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
512
	#$conf["keyForAes256"]="";
513
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
514
	#$conf["aes256Encode"]="";
515
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
516
	#$conf["qbpwcfDecode"]="false";
517
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
518
	#$conf["gpgDecrypt"]="false";
519
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
520
	#$conf["gpgId"]="";
521
	#參考資料:
522
	#sha1=>http://php.net/manual/en/function.sha1.php
523
	#md5=>http://php.net/manual/en/function.md5.php
524
	#password_hash=>http://php.net/manual/en/function.password-hash.php
525
	#password_verify=>http://php.net/manual/en/function.password-verify.php
526
	#json_decode=>https://www.php.net/manual/en/function.json-decode.php
527
	#備註:
528
	#無.
529
	$enCodeStr=authenticate::enCodeStr($conf);
530
	unset($conf);
531
 
532
	#如果執行異常
533
	if($enCodeStr["status"]==="false"){
534
 
535
		#印出結果
536
		var_dump($enCodeStr);
537
 
538
		#結束執行,回傳 shell 1
539
		exit(1);
540
 
541
		}#if end
542
 
543
	#印出結果
544
	$input=$enCodeStr["content"];
545
 
546
	}#if end
547
 
548
#印出結果
549
echo $input;