Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AES encoding #28

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration/encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ Example:

If this fits your need Change your `encoding` value to `plain`

### AES
Similar to the XOR encoding, AES (Advanced Encryption Standard) encoding is a type of symmetric encryption where the same key is used to both encrypt and decrypt a message, but different to the XOR encoding, AES doesn't settle for a one-byte affair; it operates with much logner key lengths. It is also a cipher and not an encoding. If you're trying to hide your activity the best, AES is the way to go. It's harder to decrypt than something than base64 and harder to read than the XOR encoded urls. This version of AES is also salted.

Example:
* `https://google.com`
* `U2FsdGVkX19vOrJhB+tKkRLOrTZyBrUGWHXptoNXkU9JY6st/tFfsW0Y7UzwAFUm`
* `https://www.youtube.com`
* `U2FsdGVkX18eYibgsnuW2xQsNrAqIUpsYWXMLSLKJRNyrCmeoOJzq38VBWwBSzzY`

If this fits your need Change your `encoding` value to `aes`

### Base64
Base64 is a encoding algorithm that allows you to transform any characters into an alphabet which consists of Latin letters, digits, plus, and slash. Thanks to it, Dynamic can hide URLs by turning the letters of the URL into numbers.

Expand Down
17 changes: 16 additions & 1 deletion lib/global/codec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as CryptoJS from 'crypto-js';

const xor = {
encode: (str: string | undefined, key: number = 2) => {
if (!str) return str;
Expand All @@ -24,6 +26,19 @@ const plain = {
}
}

const aes = {
encode: (str: string | undefined) => {
if (!str) return str;

return CryptoJS.AES.encrypt(str, 'dynamic').toString();;
},
decode: (str: string | undefined) => {
if (!str) return str;

return CryptoJS.AES.decrypt(str, 'dynamic').toString(CryptoJS.enc.Utf8);
}
}

const none = {
encode: (str: string | undefined) => str,
decode: (str: string | undefined) => str,
Expand All @@ -42,4 +57,4 @@ const base64 = {
}
}

export { xor, plain, none, base64 };
export { xor, plain, none, base64, aes };
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@tomphttp/bare-client": "^2.2.0-alpha",
"@tomphttp/bare-server-node": "^2.0.1",
"chalk": "^5.3.0",
"crypto-js": "^4.1.1",
"domhandler": "^5.0.3",
"esbuild": "^0.19.0",
"fastify": "^4.21.0",
Expand All @@ -33,6 +34,7 @@
},
"type": "module",
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/mime-db": "^1.43.1",
"@types/set-cookie-parser": "^2.4.2",
"execa": "^7.1.1",
Expand Down