Links

String Encryption

Babel Obfuscator provides the ability to encrypt code-inline strings using the XOR or HASH algorithm. In addition to these built-in encryption algorithms, Babel also allows for custom string algorithms to be implemented through external code or plugins. This enables users to create their own unique encryption methods tailored to their specific needs.

XOR Algorithm

The XOR algorithm used by Babel Obfuscator for string encryption is a simple one that involves XOR-ing the in-line string characters with a random integer key. This method has the advantage of allowing for faster decryption and less load time compared to other encryption algorithms.

Command Line

babel myapp.exe --string xor

MSBuild Babel Task

<PropertyGroup>
<StringEncryption>xor</StringEncryption>
</PropertyGroup>
<Babel StringEncryption="$(StringEncryption)" />

HASH Algorithm

The HASH algorithm used by Babel Obfuscator is based on hash tables addressed by integer keys. This algorithm performs both compression and encryption of string data, which can help to reduce the overall file size of the string data. However, since the compressed string data needs to be decrypted at runtime, it can have an impact on the load time of the application. Compared to the XOR algorithm, which xor-ed the inlined string characters with a random integer key, the HASH algorithm offers better protection against string decryption attacks but at the cost of a slower load time.

Command Line

babel myapp.exe --string hash

MSBuild Babel Task

<PropertyGroup>
<StringEncryption>hash</StringEncryption>
</PropertyGroup>
<Babel StringEncryption="$(StringEncryption)" />
Babel Obfuscator cannot encrypt strings defined as const because they are baked into the metadata #Blob heap and initialized directly by the CLR. However, you can convert them to static readonly (C#) or Shared ReadOnly (VB) to make them eligible for encryption.
// Strings declared const cannot be encrypted
public const string Connection = "Server=myServerAddress;Database=myDB;...";
// To encrypt, convert the above declaration to static readonly
public static readonly string Connection = "Server=myServerAddress;Database=myDB;...";

Custom String Encryption

Custom string encryption enables users to formulate their own methods for encrypting and decrypting strings, allowing for personalized obfuscation of strings. To leverage custom string encryption, users are required to define two specific methods within the target assembly: EncryptString and DecryptString. Both methods must have identical signatures, accepting a string as a parameter and returning a string, which represents either the encrypted or decrypted string, respectively. By establishing these methods, users have the flexibility to implement any custom encryption algorithm of their choice to encrypt strings in their code, granting enhanced adaptability and command over the obfuscation process.
/// <summary>
/// Encrypt a string.
/// </summary>
/// <param name="text">The string to encrypt.</param>
/// <returns>The encrypted string.</returns>
[Obfuscation(Feature = "string encryption encrypt method")]
internal static string EncryptString(string text)
{
// Encrypt the text string and return the encrypted string object.
return ...;
}
/// <summary>
/// Decrypt an encrypted string.
/// </summary>
/// <param name="text">The encrypted string.</param>
/// <returns>The decrypted string.</returns>
[Obfuscation(Feature = "string encryption decrypt method")]
internal static string DecryptString(string text)
{
// Decrypt the text string and return the decrypted string object.
return ...;
}
The EncryptString and DecryptString methods are addressed by the Obfuscation attribute with a proper Feature string, which allows Babel to identify the code entry points for encrypting and decrypting strings.
Once you have defined the EncryptString and DecryptString methods and addressed them with the proper Obfuscation attribute, you can then enable custom string encryption with Babel. To use the designed methods to encrypt/decrypt strings, you can configure Babel at the command line or within an MSBuild task, depending on your project setup and preference.

Command Line

To enable Babel custom string encryption using the command line, you can enter the command:
babel myapp.exe --strings custom

MSBuild Babel Task

If you are using the Babel task, you can enable custom string encryption by adding the following to your project file:
<PropertyGroup>
<StringEncryption>custom</StringEncryption>
</PropertyGroup>
<Babel StringEncryption="$(StringEncryption)" ... />
In addition, users can also implement custom string encryption using external plugins (see Babel Obfuscator Plugins).
Last modified 3d ago