Feature Based Licenses

Babel Obfuscator includes a licensing feature that allows you to generate feature-based licenses for your obfuscated code. This means that you can create licenses that unlock specific features or functionality within your application based on the license key that is provided.

One way to implement this is by using code encryption in combination with Babel Licensing. You can use Babel Obfuscator to encrypt your code and then generate a license key that unlocks specific encrypted sections of the code. This way, you can provide different license levels or feature sets based on the user's needs.

For example, suppose you have an application with three levels of functionality: Standard, Professional and Enterprise. You can use Babel Obfuscator to encrypt the Enterprise features of the application and then generate a license key that unlocks those features. You can then provide different license keys to users based on their subscription level, with each key unlocking the appropriate set of features.

To implement this, you would use Babel Licensing to generate the license keys and verify them at runtime. When the user enters a license key, your application uses Babel Licensing to validate the key and determine which features should be unlocked. The encrypted sections of the code would then be decrypted and made available to the user.

The source code of the example that demonstrates feature-based licensing with code encryption is available on GitHub

git clone https://github.com/babelfornet/license-features-example.git

The example references the Babel Licensing NuGet package to use its features. The example code will include an implementation of the LicenseManager class, which provides methods for checking the validity of a license and the presence of specific features.

public ILicense ValidateLicense()
   // To validate the license, only the public key is required.
   // The private key is only used to sign the license, and in production the private key
   // should not be distributed with the application.
   // The public key should be distributed with the application and used to validate the license.

   // The following signature provider can be used to create and validate the license
   // as includes both the private key and the public key.
   var signature = CreateSignature();

   // The public key string can be embedded into the application and used to create a signature
   // provider used only to validate the license.
   string publicKey = signature.ExportKeys(publicKeyOnly: true);

   // To create the RSASignature from the public key use the following code
   var validatingSignature = RSASignature.FromKeys(publicKey);

   // And assign the validating signature provider to the license manager
   var licenseManager = new XmlLicenseManager();
   licenseManager.SignatureProvider = validatingSignature;

   license = licenseManager.Validate(File.ReadAllText(LicenseFileName), typeof(LicenseManager), this);
   return license;

The example will also include the code to generate an XML license file that specifies the license information, such as the expiration date, licensed features, and product information.

Note that the code made available in the example to generate the license is only for demonstration purposes and must not be included in production.

Code encryption can be used to protect the code that makes up the features of a software application from being used without the proper license file. This can be achieved by encrypting the code that implements a particular feature and requiring a password to decrypt and execute the code.

[Obfuscation(Feature = "msil encryption:internal=true;source=feature1;cache=false;password=aR&tj4i7u@", Exclude = false)]
internal class Feature1
   public Feature1() { }

   public string DoTask()
      return "Feature1: " + Add(7, 8);

   public int Add(int a, int b) => a + b;

The password can be obtained from a license file that is generated based on the features that the user has licensed.

Babel Obfuscator uses the Obfuscation attribute to mark the code that makes up the feature to be protected and specifies the method that should be called at runtime to retrieve the password needed to decrypt and execute the protected code. This method is typically a small function that retrieves the password from a license file or a licensing server. The password is then used by Babel Obfuscator to decrypt the protected code during runtime, ensuring that only licensed users can access the feature.

[Obfuscation(Feature = "msil encryption get password")]
internal static string GetSourcePassord(string source)
   var lm = LicenseManager.Instance;

   var feature = lm.License.Features.FirstOrDefault(item => item.Name == source);
   if (feature == null)
      throw new ApplicationException(source + " not found");

   return Encoding.UTF8.GetString(feature.Data);

Once the example is compiled, run the obfuscation project Obfuscate.babel to protect the application features with Code Encryption.

You can start the protected application and generate a license for the three different application editions provided: Standard, Professional and Enterprise. Each edition unlocks an incremental number of features, meaning that the higher the edition you license, the more features you will be able to use within the application. So, generating a license for the Enterprise edition will unlock all the features, while generating a license for the Standard edition will only unlock a subset of the features.

The LicenseManager class will check for a valid license and the presence of the requested features. If the license is valid and the features are enabled, the application will allow the user to access those features.

Overall, using code encryption with Babel Licensing can provide a powerful way to create flexible and feature-rich applications while still protecting your code from reverse engineering and piracy.

Last updated