openresty / lua-resty-string

String utilities and common hash functions for ngx_lua and LuaJIT
429 stars 143 forks source link

how to implement aes-128-ecb encryption with php or golang #95

Open Doraemonoops opened 1 year ago

Doraemonoops commented 1 year ago

here is the lua code

local aes = require 'resty.aes'

local cipher = aes:new('0123456789123456', nil, aes.cipher(128, 'ecb'))

print(ngx.encode_base64(cipher:encrypt('foobar')))

the output should be rTeNAHEZtzsyn1dDAujGgQ==

blow is my php code

var_dump(base64_encode(openssl_encrypt('foobar', 'aes-128-ecb', '0123456789123456', OPENSSL_RAW_DATA)));

the output should be AIIiZT3RO/bkseLE0Mcopg==

how can i get the lua result with php code. pls help me, thanks.

shangwing commented 8 months ago

local cipher = aes:new('0123456789123456', nil, aes.cipher(128, 'ecb'),{ iv ='\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'})

dugongzi commented 8 months ago

抱歉我一般不看Gmail,我用的是QQ邮箱,若你要联系我,请加我微信:a1657917789 我的qq:3113143666

shangwing @.***>于2024年3月26日 周二15:31写道:

local cipher = aes:new('0123456789123456', nil, aes.cipher(128, 'ecb'),{ iv ='\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'})

— Reply to this email directly, view it on GitHub https://github.com/openresty/lua-resty-string/issues/95#issuecomment-2019562365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM5TE7ZZRCQOMW7A232OR7LY2EP6PAVCNFSM6AAAAAAZPYNHI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJZGU3DEMZWGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>