使用encrypt进行RSA加密,当数据为formData时,
lua-multipart 模块解析后 显示“ FormData”的实例.请问需要怎么办?
`2020/06/26 22:52:45 [info] 30346#30346: *4239 [lua] Princopal.lua:17: RW1OO7hAfPHdavccK2XBWYBSEScWpHzsudt3Pwh0oFFu4oOFMHq05dxQmVq9s+/f8nSgQ77mjySe6RwgF3N93t5+2ifJtjCrKG7lFnIhSNN7w8FQ19L+ny/bzIOyHLH0K5PsgW4k17QNP79TH0XCTk4YHeG+45Decw8Zv3iBkEPCMqVy5ByuYmImpz3ln3u/FXNiKXsFogz59p7KRGhvB33RJ41VymWBfSN4K3ls9RjEj2KIj6mZ4+lMXn+R7bKhCpAdL8/axriezTII/2NkBnzuXXPHG2iAO1qtjOUQkS0DEfqS/d6rQxT42dUSsCu/zM3S3q3ENLULkKUWA+O6dA==, client: 121.32.48.11, request: "POST /Princopal HTTP/1.1",
2020/06/26 22:52:45 [info] 30346#30346: *4239 [lua] Princopal.lua:19: Instance of 'FormData', client: 121.32.48.11, request: "POST /Princopal HTTP/1.1",
`local cjson = require "cjson.safe" --Json解析模块
local resty_rsa = require "resty.rsa" --对称加密解密模块
local Multipart = require("multipart") --解析fromData表单
local method = ngx.req.get_method() --获取是Get还是Post
local private_file = io.open("/Nginx/lua/flutter_private.pem", "r") --打开私匙文件
local private_Key = private_file:read("*a") --读取私钥内容
local priv = resty_rsa:new({private_key = private_Key, key_type = resty_rsa.KEY_TYPE.PKCS1}) --创建一个 对象
local head = ngx.req.get_headers() --获取请求头
if method == "POST" then --如果是Post的话
ngx.req.read_body() --读取Post_Body
local Encryptionbody = ngx.req.get_body_data() --获取消息体,此时是被加密的消息体
ngx.log(ngx.INFO, Encryptionbody)
local body = priv:decrypt(ngx.decode_base64(Encryptionbody)) --解析出来,此时是真正的消息
ngx.log(ngx.INFO, body)
if body == nil then
ngx.exit(500)
end
local multipart_data = Multipart(body, head["content-type"])
body = multipart_data:tostring()
ngx.log(ngx.INFO, body)
--判断是Json格式还是其他的格式
-- local str = cjson.encode(priv:decrypt(ngx.decode_base64(body))) --解析消息体,然后转换为Json
if body then
ngx.say(body)
end
ngx.exit(200)
end
if method == "GET" then
end`