In the world of JavaScript reverse engineering, encryption algorithms shine like stars. Experienced reverse engineers can accurately identify the type of encryption based on the length of the ciphertext and the structure of the code. Do you also want to uncover the secrets behind it?
Familiarity with various encryption algorithms not only enhances your reverse engineering skills but also allows you to debug with ease! I have a small suggestion: beginners can start with common encryption algorithms and gradually expand to more complex logic, which will yield better results!
Below, I will share some common encryption algorithms!
Base64 Encoding
Base64 is a method of encoding binary data into ASCII characters, commonly used for transmitting data in text environments, such as email attachments, JSON, and HTML embedded images. It is not encryption, but merely encoding, aimed at making data more ‘friendly’, but it does not provide security.
Working Principle
- Split each byte (8 bits) of the input data into groups of 6 bits.
- Map these 6 bits using a table of 64 characters (A-Z, a-z, 0-9, +, /).
- Convert every 3 bytes (24 bits) into 4 Base64 characters, padding with ‘=’ if necessary.
Code Example
// Native JavaScript implementation of Base64 encoding and decoding
const text = "Hello, Grok!";
// Encoding
const encoded = btoa(text);
console.log("Base64 encoding:", encoded); // "SGVsbG8sIEdyb2sh"
// Decoding
const decoded = atob(encoded);
console.log("Base64 decoding:", decoded); // "Hello, Grok!"
Symmetric Encryption Algorithms
Symmetric encryption algorithms use the same key for both encryption and decryption, offering fast speed and high efficiency, making them a common choice for data encryption. However, the secure distribution and management of the key is a core challenge.
Working Principle
- Encryption: The sender uses the key to convert plaintext into ciphertext.
- Decryption: The receiver uses the same key to revert the ciphertext back to plaintext.
- It relies on complex mathematical operations, such as permutation and substitution.
Typical Algorithms
1. AES (Advanced Encryption Standard) is the ‘star player’ among symmetric encryption algorithms, widely used for data protection. It uses the same key for encryption and decryption, is fast, and highly secure, making it the preferred choice for modern applications.
2. DES (Data Encryption Standard) is the ‘veteran’ of symmetric encryption algorithms, developed by IBM and adopted as a standard by the U.S. government in 1977. It uses a single key for encryption and decryption and inspired many modern encryption algorithms (like AES). However, due to its shorter key length, it is no longer suitable for high-security scenarios.
Code Example
Environment Setup1. Install
<span>node.js</span>
following the guide at https://mp.weixin.qq.com/s/ztssXGmByDOz9WRezvhZOg
Install the<span>crypto-js</span>
library
npm install crypto-js
AES Encryption Algorithm Example
const CryptoJS = require('crypto-js'); // Importing the library
// Define key and message
const key = "mysecretkey12345"; // 16 bytes (128 bits)
const message = "Hello, AES!";
// Encrypt (default ECB mode)
const encrypted = CryptoJS.AES.encrypt(message, key).toString();
console.log("AES encryption:", encrypted);
// Decrypt
const decrypted = CryptoJS.AES.decrypt(encrypted, key).toString(CryptoJS.enc.Utf8);
console.log("AES decryption:", decrypted); // "Hello, AES!"
DES Encryption Algorithm Example
const CryptoJS = require('crypto-js'); // Importing the library
// Define key and message
const key = "8bytekey"; // 8 bytes (64 bits)
const message = "Hello, DES!";
// Encrypt
const encrypted = CryptoJS.DES.encrypt(message, key).toString();
console.log("DES encryption:", encrypted);
// Decrypt
const decrypted = CryptoJS.DES.decrypt(encrypted, key).toString(CryptoJS.enc.Utf8);
console.log("DES decryption:", decrypted); // "Hello, DES!"
To summarize, in practice, we can first search for keywords like<span>decrypt</span>
or <span>encrypt</span>
to locate the encryption points, and then based on whether the encryption logic contains keywords like <span>DES</span>
or <span>AES</span>
, we can pinpoint the location and simulate locally to obtain the encryption and decryption results. However, non-standard encryption algorithms or salted encryption may also exist. Additionally, some encryption algorithms are also common in JavaScript reverse engineering, such as hash algorithms (MD5, SHA, HMAC), asymmetric encryption algorithms (RSA, ECC, DSA), and SM algorithms.
If you want to learn about JavaScript reverse engineering, feel free to follow me, and you can message me or scan the code to join the study group. If this article has been very helpful to you, please like, share, and forward it!

See you in the next article!