Logo

dev-resources.site

for different kinds of informations.

JavaScript Base-32 Encryption

Published at
11/16/2024
Categories
encryption
javascript
webdev
Author
wangliwen
Categories
3 categories in total
encryption
open
javascript
open
webdev
open
Author
9 person written this
wangliwen
open
JavaScript Base-32 Encryption

In JavaScript programming, eval is often used to protect privacy, encrypt code execution, and run scripts that one does not want others to know about, such as common practices like eval encryption, U encryption, JJEncode encryption, all of which utilize eval for code execution.

However, the string "eval" itself is a very obvious characteristic, making it too easy to search for, and then replace with console.log, alert, thereby achieving reverse engineering and obtaining the content executed by eval.

Is there a way to also hide eval so that it's not so easily discovered? Of course, the following introduces one method: Base-32 Encryption.

The principle is as follows: eval is a member function of window in browsers; in the Node.js environment, it is a member function of global. Therefore, eval can also be written as:
window.eval, global.eval, or window["eval"], global["eval"].

This means that eval has been transformed into a string form. Since it is a string, it becomes easier to encrypt. For example, the "eval" string can take on another form:
(14).toString(32)+(31).toString(32)+(10).toString(32)+(21).toString(32)

Or, to avoid having a uniform feature after encryption, the value passed to toString can also be altered, such as changing 14 to 10+1+3:
window[(10+1+3).toString(32)+(20+1+10).toString(32)+(10).toString(32)+(21).toString(32)]

This uses the toString(base) method to convert a number to its string representation in the specified base. In the above example code, the base is 32, meaning numbers will be converted to strings in base 32.

(14).toString(32): The number 14 is converted to base 32, which is "e". (31).toString(32): The number 31 is converted to base 32, which is "v". (10).toString(32): The number 10 is converted to base 32, which is "a". (21).toString(32): The number 21 is converted to base 32, which is "l".

When concatenated with plus signs, they form the string "eval".

Further Base-32 character correspondence:
a: (10).toString(32) -> "a"
b: (11).toString(32) -> "b"
c: (12).toString(32) -> "c"
d: (13).toString(32) -> "d"
e: (14).toString(32) -> "e"
f: (15).toString(32) -> "f"
g: (16).toString(32) -> "g"
h: (17).toString(32) -> "h"
i: (18).toString(32) -> "i"
j: (19).toString(32) -> "j"
k: (20).toString(32) -> "k"
l: (21).toString(32) -> "l"
m: (22).toString(32) -> "m"
n: (23).toString(32) -> "n"
o: (24).toString(32) -> "o"
p: (25).toString(32) -> "p"
q: (26).toString(32) -> "q"
r: (27).toString(32) -> "r"
s: (28).toString(32) -> "s"
t: (29).toString(32) -> "t"
u: (30).toString(32) -> "u"
v: (31).toString(32) -> "v"

Of course, besides this, other algorithms can also be used, for example, in browsers, the base64 string โ€œZXZhbA==โ€ can be decoded using atob to get โ€œevalโ€: Expanding on this, this method can be used not only to hide eval but also to conceal other methods. For instance, consider this line of code suitable for browser execution:
window[(10).toString(32)+(21).toString(32)+(14).toString(32)+(27).toString(32)+atob("dA==")]("moc.rotacsufbo-sj".split("").reverse().join(""));

What would this output? Try it out yourself.

encryption Article's
30 articles in total
Favicon
Encryption in React Native apps enhances data security, protecting user information and ensuring privacy. However, it also presents challenges, such as performance overhead and complex implementation
Favicon
A Deep Dive into WhatsAppโ€™s Encryption: Identity, Keys, and Message Security
Favicon
The Birthday Paradox: A Statistical Breakdown and How it Relates to Online Security
Favicon
Obfuscating โ€œHello world!โ€ obfuscate on Python
Favicon
Introducing Inline Cryptography Toolkit: Simplify Encryption, Decryption, and Hashing in VS Code ๐Ÿš€
Favicon
Advantages of Asymmetric Encryption with Random Public and Symmetric Private Keys
Favicon
Cloud Security Challenges and Encryption, Identity Management, and Compliance
Favicon
Microsoft Certified Azure Administrator Associate Exam (AZ-104) Lab Preparation #5: Azure Disk Encryption
Favicon
Encryption: ciphers, digests, salt, IV
Favicon
The Evolution of Hashing Algorithms: From MD5 to Modern Day
Favicon
Email Security and Data Protection for Startups: Affordable Solutions
Favicon
Understanding SNI (Server Name Indication) and Modern Encryption Solutions
Favicon
What is RSA Asymmetric Encryption? Basics, Principles and Applications
Favicon
Encryption Vs. Decryption: Whatโ€™s the Difference?
Favicon
Laravel Data Encryption and Decryption
Favicon
Unveiling A Groundbreaking Open-Source Encrypted Machine Learning Framework
Favicon
Secure Text Encryption and Decryption with Vanilla JavaScript
Favicon
Understanding SSL/TLS: The Role of Encryption and Security Protocols in Internet Communication
Favicon
Implications for Encryption and Cybersecurity with Quantum Computing
Favicon
How to Generate Your Own Public and Secret Keys for PGP Encryption
Favicon
Does S/MIME Encrypt Emails and Attachments?
Favicon
What is Token Signing in Software Publisher Certificate?
Favicon
Encryption Symmetric
Favicon
Secret management for the layman
Favicon
JavaScript Base-32 Encryption
Favicon
Comprehensive Encryption and Security Service in NestJS: Argon2 Hashing, Token Generation, and AES Encryption
Favicon
Difference Between Encryption and Hashing ๐Ÿ”๐Ÿ”‘
Favicon
Ransomware Explained: How It Works and Best Defense Mechanisms to Protect Your Data
Favicon
Debunking Most Common Cloud Computing Myths & Misconceptions
Favicon
Implementing HTTP Request and Response Encryption in ASP.NET Core with Custom Attributes

Featured ones: