Creating Secure URL using Ciphering

Sample script

 const xorCipher = (text, key) => {
                    let result = '';
                    for (let i = 0; i < text.length; i++) {
                        result += String.fromCharCode(text.charCodeAt(i) ^ key.charCodeAt(i % key.length));
                    }
                    return result;
                };
                const timeStamp = JSON.stringify(Date.now());
                const cipheredText = `${xorCipher(soId + '-' + routeId, timeStamp)}`;
                log.debug("cipheredText", JSON.stringify(cipheredText));
                let base64Val = encode.convert({
                    string: cipheredText,
                    inputEncoding: encode.Encoding.UTF_8,
                    outputEncoding: encode.Encoding.BASE_64
                });
                const passCode = encodeURIComponent(base64Val);
                let schedulingUrl = url.resolveScript({
                    scriptId: 'customscript_jj_sl_fetchupd_so_ahap1890',
                    deploymentId: 'customdeploy_jj_sl_fetchupd_so_ahap1890',
                    returnExternalUrl: true,
                    params: {
                        soId: soId,
                        routeId: routeId,
                        dateStampId: timeStamp,
                        passCodeId: passCode
                    }
                });
                log.debug('schedulingUrl', schedulingUrl);
                return schedulingUrl;

Leave a comment

Your email address will not be published. Required fields are marked *