openresty用AES/ECB/NoPadding 128位解密,openrestynopadding


由于各个语言在默认填充方式的不同,导致跨编程语言加解密失败。
lua 解密java 用AES/ECB/NoPadding 128位加密结果示例:
ase 使用了resty.aes,底层调用了C语言的spenssl

local str = require "resty.string"

--ECB 方式无需iv,传递一个16字节的iv以便用原始key进行EVP_DecryptInit_ex初始化
local
price_decode = aes:new(key,nil,aes.cipher(128,"ecb"),{iv=dspkey})
local
base_decode_bytes = ngx.decode_base64(ad_price)
ngx
.log(ngx.DEBUG,"base_decode_price_byte:" .. str.to_hex(base_decode_price))
--补充一个空块的加密结果,以适应decrypt函数的调用
base_decode_bytes = base_decode_bytes .. pad_bytes
local
price = price_decode:decrypt(base_decode_bytes)


相关内容

    暂无相关文章