-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestdid_func.lua
More file actions
58 lines (48 loc) · 1.56 KB
/
Copy pathtestdid_func.lua
File metadata and controls
58 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require "ngx" --ngx库
local config = require "config"
local tools = require "tools"
local conn = require "redis_conn"
local http = require "resty.http"
local cjson = require "cjson"
--测试deviceid是否有效的接口,内部使用
local args = ngx.req.get_uri_args()
local ip = args['ip'] or ''
ngx.log(ngx.INFO, string.format("TEST DID IP: %s", ip))
local agent = args['agent'] or ''
ngx.log(ngx.INFO, string.format("TEST DID AGENT: %s", agent))
local key = args['key'] or ''
ngx.log(ngx.INFO, string.format("TEST DID KEY: %s", key))
local iv = args['iv'] or ''
ngx.log(ngx.INFO, string.format("TEST DID IV: %s", iv))
local did = args['did'] or ''
ngx.log(ngx.INFO, string.format("TEST DID DID: %s", did))
local todeaes = args['todeaes'] or ''
ngx.log(ngx.INFO, string.format("TEST DID todeaes: %s", todeaes))
--开始生成加密串did
local toEncryptStr = tools.sha256(ip..config.md5Gap..agent)
ngx.log(ngx.INFO, string.format("TEST DID toEncryptStr: %s", toEncryptStr))
--加密串
local aesStr = tools.aes128Encrypt(toEncryptStr, key)
ngx.log(ngx.INFO, string.format("TEST DID toEncryptStr: %s", toEncryptStr))
--解密
local deaesStr = tools.aes128Decrypt(todeaes, key)
--解密串
local decodeDid
if did and did ~= '' then
decodeDid = tools.aes128Decrypt(did, key)
ngx.log(ngx.INFO, string.format("TEST DID decodeDid: %s", decodeDid))
else
decodeDid = ''
end
local tmpTable = {
ip=ip,
agent=agent,
key=key,
iv=iv,
nginx_toEncryptStr=toEncryptStr,
nginx_aesStr=aesStr,
client_decodeDid=decodeDid,
deaesStr=deaesStr,
}
ngx.header["Content-Type"] = 'text/plain'
ngx.say(cjson.encode(tmpTable))