forked from vadimpronin/guacamole-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt_token.js
53 lines (41 loc) · 1.2 KB
/
encrypt_token.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import crypto from "node:crypto";
const CIPHER = "aes-256-cbc";
const SECRET_KEY = "MySuperSecretKeyForParamsToken12";
const tokenObject = {
connection: {
type: "rdp",
settings: {
hostname: "10.0.0.12",
username: "Administrator",
password: "pAsSwOrD",
"enable-drive": true,
"create-drive-path": true,
security: "any",
"ignore-cert": true,
"enable-wallpaper": false,
},
},
};
function encryptToken(value) {
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(CIPHER, Buffer.from(SECRET_KEY), iv);
let encrypted = cipher.update(JSON.stringify(value), "utf8", "base64");
encrypted += cipher.final("base64");
const data = {
iv: iv.toString("base64"),
value: encrypted,
};
const json = JSON.stringify(data);
return Buffer.from(json).toString("base64");
}
const originalToken = JSON.stringify(tokenObject, null, 2);
const token = encryptToken(tokenObject);
const urlencodedToken = encodeURIComponent(token);
console.log("Parameters:");
console.log(originalToken);
console.log("\n");
console.log("Encrypted token:");
console.log(token);
console.log("\n");
console.log("Use this token in the URL:");
console.log(`ws://localhost:8080/?token=${urlencodedToken}`);