Encrypt Code and Data

This feature allows you to encrypt key application data or source code with separate parameters and keys (not the same ones that are used to encrypt/decrypt license). You can include encrypted data and source code into your project and then decrypt them using functionality provided by Manco.Licensing.License class. After that data can be used in the application and decrypted code can be dynamically compiled and loaded. To encrypt text:

  1. Main Menu: Action->Encrypt Text.
  2. Context Menu: right click on the License Type node or License Type View and select Encrypt Text.

You will see the following dialog

Encryption Text Form

If you’ve not generated crypto parameters and crypto key for text encryption yet, then click “Generate Crypto Params” button. In other case, select name of the custom value will be used as crypto parameters and crypto key in the corresponding dropdowns. Copy and paste, or enter the text (data or source code) you’d like to encrypt to the left text box (“Source Text”). Click “Encrypt” button. Encrypted version of the text appears in the right text box (“Encrypted Text”). Click “To Clipboard” button to get encrypted text to the clipboard. Paste it to the proper place in your project. If you need more encryption, then delete old text in the “Source Text” text box and put new one there and click “Encrypt”. In the other case click “Close” button.

Using of the encrypted code

There are several ways how you can use encrypted source code in your application. The easiest way is define an interface in your product that declares methods with functionality you’d like to encrypt. After that, class that will be encrypted should be declared as one that implements this interface. Get source code of it and encrypt. Put encrypted code to the text file included to your project and mark it as “Embedded Resource”. Add to your project code that will load encrypted code. The resulting code could looks like the following:

public interface IEncryptedRunner
	void Run();

public class Executor
	private IEncryptedRunner m_Runner;

	public Executor(Manco.Licensing.License aoLicense)
		Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("EncryptedRunner.txt");
		if(stream != null)
			StreamReader reader = new StreamReader(stream);
			string lsCode = reader.ReadToEnd();

			// Load interface from the protected storage
			Assembly loAssembly = aoLicense.LoadEncryptedAssembly(lsCode, 
				new string[] {

			// Get type of the class to be executed
			Type loType = loAssembly.GetType("Manco.Test.Evaluator");

			// Create object to invoke method on it
			m_Runner = (IEncryptedRunner)Activator.CreateInstance(loType);

	public void Run()

[Visual Basic] 
Public Interface IEncryptedRunner
    Sub Run()
End Interface

Public Class Executor
    Private m_Runner As IEncryptedRunner

    Public Sub New(ByVal aoLicense As Manco.Licensing.License)
        Dim callingAssembly As System.Reflection.Assembly.Assembly 
        callingAssembly = System.Reflection.Assembly.GetCallingAssembly()
        Dim stream As stream = callingAssembly.GetManifestResourceStream("EncryptedRunner.txt")
        If Not stream Is Nothing Then
            Dim reader As StreamReader = New StreamReader(stream)
            Dim lsCode As String = reader.ReadToEnd()

            Dim lsaDLLToLoad() As String = { _
                "System.dll", _
                "System.Drawing.dll", _
                "System.Windows.Forms.dll" _

            ' Load interface from the protected storage
            Dim loAssembly As System.Reflection.Assembly = aoLicense.LoadEncryptedAssembly(lsCode, _
             aoLicense.GetCustomValue("CryptoParams"), _
             aoLicense.GetCustomValue("CryptoKey"), _
             "VisualBasic", _
             lsaDLLToLoad _

            ' Get type of the class to be executed
            Dim loType As Type = loAssembly.GetType("Manco.Test.Evaluator")

            ' Create object to invoke method on it
            m_Runner = CType(Activator.CreateInstance(loType), IEncryptedRunner)
        End If
    End Sub

    Public Sub Run()
    End Sub
End Class

Prepare Source Code for Encryption

As you could see from the previous section, manual preparation of the source code for encryption takes a time. Debugging of the encrypted code using Visual Studio or other IDE seems to be impossible. How to optimize this process? Manco License Generator provides functionality for automatic preparation code for encryption. It creates calling interface, wrapper class and code for encryption for existing class. This allows you design, implement and debug your class in a regular manner and encrypt it in a few minutes just before issue a product. To prepare source code for encryption click “Prepare Source” button on the “Encrypt Text” form. You will see the following form:

Prepare Source Code

You should put code you’d like to prepare to the “Original source code” text box. You can do it using Copy-Paste or “Load Original” button.

Select programming language which has been used to code class. C# and Visual Basic .NET are currently supported.

The source code will be compiled during preparation, so you should add necessary references. To add common assemblies are located in the GAC check them in the “GAC Assemblies” list and click “Add” button. To add other assemblies use “Add File” button. If you are using other classes from your assemblies in the code to be encrypted, then don’t forget add your executable or DLL to the references. To remove unnecessary assemblies from the references check them in the “References” list and click “Remove” button.

Click “Prepare” button. Firstly the source code will be compiled. You can see message box with compilation error list. If you are preparing ready for use class then most often it means that you’ve forgot to add some references. Check them and repeat. If process would finish successfully then “Wrapper Class” and “Code to be encrypted” text boxes are filled with prepared code.

The “Wrapper Class” text box contains definition of the calling interface and code of the wrapper class. The “Code to be encrypted” text box contains your class source code with changed class name and implemented calling interface. Click “Save & Exit” button. You will be prompted for file name of the wrapper class and code to be encrypted. It’s strong necessary to save wrapper class, because it should be included to your project instead of original one. It’s up to you to save code to be encrypted, but we suggest doing it.

When “Prepare Source Code” form would be closed you will see “Encrypt Text” form with “Source Text” textbox filled with code ready for encryption. Click “Encrypt” button. Encrypted version of the code appears in the right text box (“Encrypted Text”).

Now you can copy encrypted code to the clipboard and paste it in the text file in your project or click “Save to file” button and save it as text file.

Don't forget remove original class from your project and include wrapper class and encrypted source to it. In the Visual Studio you can just set “Build Action” property for original source to the “None” and for wrapper class to the “Compile”. We suggest include encrypted source to your project as Embedded resource.

Now your executable or DLL contains only encrypted version of the critical code.

.NET Licensing Pro Home Page