local b64 = require("ngx.base64") -- only contains URL-variants if not b64["decode_base64"] then b64.decode_base64 = function(base64) base64 = base64:gsub("%+", "-") base64 = base64:gsub("/", "_") return b64.decode_base64url(base64) end end if not b64["encode_base64"] then b64.encode_base64 = function(plaintext) local plain, err = b64.encode_base64url(plaintext) if not plain then return nil, err end plain = plain:gsub("_", "/") return plain:gsub("%-", "+"), nil end end return b64