Malformed URI when encrypting string using md5
titan1230 opened this issue · comments
Kindly, help me solve this error of Malformed URI when encrypting string using md5.
The error is:
URIError: URI malformed
at decodeURIComponent (<anonymous>)
at Object.util.decodeUtf8 (/home/pi/Projects/scratcher/node_modules/node-forge/lib/util.js:1671:10)
at ByteStringBuffer.util.ByteStringBuffer.toString (/home/pi/Projects/scratcher/node_modules/node-forge/lib/util.js:716:15)
at /home/pi/Projects/scratcher/src/routes/offerwall/index.ts:32:99
at Generator.next (<anonymous>)
at /home/pi/Projects/scratcher/src/routes/offerwall/index.ts:8:71
at new Promise (<anonymous>)
at __awaiter (/home/pi/Projects/scratcher/src/routes/offerwall/index.ts:4:12)
at /home/pi/Projects/scratcher/src/routes/offerwall/index.ts:12:36
at Layer.handle [as handle_request] (/home/pi/Projects/scratcher/node_modules/express/lib/router/layer.js:95:5)
The code is:
import { md5 } from "node-forge";
const sub_id = encodeURIComponent(req.query.sub_id!.toString());
const amount = encodeURIComponent(req.query.amount!.toString());
const signature = req.query.signature!.toString();
const secret_key = encodeURIComponent(process.env.SECRET_KEY!);
if (!amount || !sub_id || !signature) {
res.send("0");
return;
}
let conn;
const md = md5.create()
const validation_signature = md.update(sub_id + ":" + amount + ":" + secret_key).digest().toString();
Your help would be greatly appreciated.