我使用如下的示例代码,加密一个字符串"you and me 2016"
:
local aes = require "resty.aes"
local str = require "resty.string"
local aob = aes:new("this is ","ttInetCp",aes.cipher(256,"cbc"), aes.hash.sha512, 5)
function main()
local ens = aob:encrypt(tostring(ngx.time()).."you and me 2016")
ngx.say("ensbefore:",ens)
ngx.say("ensafter:",str.to_hex(ens))
ngx.say("ens:",type(ens))
local ovalue = aob:decrypt(ens)
ngx.say(ovalue)
end
main()
下面是curl运行结果:
➜ tmp5 curl .....
ensbefore:�m���i����L?�0P?��l@�� M5/q���
ensafter:aa6dad1c9d826993fcffbf4c3f14af30503fdae66c409ceb204d352f7182a4d6
ens:string
1520496778you and me 2016
这里我有一个疑问,如果想解密的话,必须要用ensbefore这个变为16进制之前的原字符串。
我想问的是能否用hash过后的字符串ensafter来进行解密呢?也就是说只有这样的输入aa6dad1c9d826993fcffbf4c3f14af30503fdae66c409ceb204d352f7182a4d6 时,可否进行解密?