lua-resty-core icon indicating copy to clipboard operation
lua-resty-core copied to clipboard

b64.encode_base64url problem

Open axpwx opened this issue 2 years ago • 3 comments

local str = 'CgIAiFs24JOIbXrLAAAAPBwznGIAAAAqwQPxMwAAABU94'
res, err = b64.decode_base64url(str)
if err then
    ngx.log(ngx.ERR, err)
    -- output: invalid input
end

openresty: 1.19.9.1 resty.core: 0.1.22

axpwx avatar Mar 14 '23 01:03 axpwx

✗ echo -n CgIAiFs24JOIbXrLAAAAPBwznGIAAAAqwQPxMwAAABU94 | base64 -d 

[6ӈmzɼ3b*󿿃󱓽base64: invalid input

zhuizhuhaomeng avatar Mar 14 '23 02:03 zhuizhuhaomeng

@zhuizhuhaomeng

echo -n CgIAiFs24JOIbXrLAAAAPBwznGIAAAAqwQPxMwAAABU94 | base64 -d | xxd -ps
base64: invalid input
0a0200885b36e093886d7acb0000003c1c339c620000002ac103f1330000
00153d

I can extract the string "5b36e093".

If decode_base64url has "loose mode", this code be works:

local str = 'CgIAiFs24JOIbXrLAAAAPBwznGIAAAAqwQPxMwAAABU94'
res, err = b64.decode_base64url(str)
if res then
    tohex(res)
    ...
else
    -- err
end

axpwx avatar Mar 14 '23 05:03 axpwx

I think we won't support 'loose mode' in the near feature.

zhuizhuhaomeng avatar Mar 15 '23 12:03 zhuizhuhaomeng