From a123f009d976a307f4da7021e6e6a2b181c05c70 Mon Sep 17 00:00:00 2001 From: Pablo Diehl Date: Mon, 22 Jan 2024 15:42:16 -0300 Subject: [PATCH] feat: Add node js sample --- secure_token.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 secure_token.js diff --git a/secure_token.js b/secure_token.js new file mode 100644 index 0000000..32abccd --- /dev/null +++ b/secure_token.js @@ -0,0 +1,16 @@ +const crypto = require('crypto'); + +const secret = 'mysecret'; +const uri = '/my/uri'; +const expire = '1470055000'; + +const md5 = crypto.createHash('md5'); +md5.update((secret + uri + expire), 'utf-8'); +const token = Buffer.from(md5.digest()).toString('base64').replace(/=|\+|\//g, (match) => ({ + '=': '', + '+': '-', + '/': '_', +}[match])); + +console.log(`http://www.example.org${uri}?st=${token}&e=${expire}`); +