用命令行对字符串“this is a example” 加密并使用base64命令对其进行编码并将结果存入data_base64.txt
$ cat data_test.txt
this is a example
$ openssl rsautl -encrypt -in data_test.txt -inkey public.keyx -pubin -out data_en.txt
$ cat data_en.txt|base64 > data_base64.txt
$ cat data_base64.txt
edPtbJzcyhTnI74BbXj2UhAbpmAIuXCrQEm8Ie5gRZqMDvAgbofwX1k/R9ZylPVx9XjRq2rwISb6
EgnFycFD1Wy/UOUbVtcr/3B4rvJnQXNtC6VvpzXogkdcMCcobrKWxGCWIw3fvckXKW8fmITUUSPd
Q2f5yEAX+B+2CNxcE0M=
用命令行decode data_base64.txt 并使用私钥解密
$ cat data_base64.txt|base64 -d > data_en_decoded.txt
$ openssl rsautl -decrypt -in data_en_decoded.txt -inkey private.key -out data_de.txt
$ cat data_de.txt
this is a example
nginx配置文件
$ cat nginx.conf
worker_processes 1; #nginx worker 数量
error_log logs/error.log; #指定错误日志文件路径
events {
worker_connections 1024;
}
http {
server {
listen 6699;
location / {
default_type text/html;
content_by_lua_block {
local file = io.open('/home/work/local/openresty/conf/data_base64.txt', 'r')
local test = file:read('*all')
file:close()
ngx.say(test)
ngx.say(ngx.decode_base64(test))
}
}
}
}
HTTP/1.1 200 OK
Date: Thu, 10 May 2018 02:32:10 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
edPtbJzcyhTnI74BbXj2UhAbpmAIuXCrQEm8Ie5gRZqMDvAgbofwX1k/R9ZylPVx9XjRq2rwISb6
EgnFycFD1Wy/UOUbVtcr/3B4rvJnQXNtC6VvpzXogkdcMCcobrKWxGCWIw3fvckXKW8fmITUUSPd
Q2f5yEAX+B+2CNxcE0M=
nil
可以看到ngx.say(ngx.decode_base64(test))结果是nil