Constant Encryption

Performance: Medium 🔐Potency: High 🧠Resilience: High

Understanding the protection

Constant encryption obfuscation is a technique used to encrypt constants in a program, such as string literals, integer values, and other constant types. This is done to make it harder for attackers to access sensitive information and to make the program more difficult to reverse engineer.

It is important to note that constant encryption obfuscation should not be used to protect business critical values such as database passwords or other forms of logins. These values should be stored and managed securely using other methods, and not encrypted within the program code.

The main reasons why constant encryption obfuscation is a good idea for C# or .NET applications are:

  • Protection of sensitive information: By encrypting constants in the program, it makes it harder for attackers to access sensitive information.

  • Improved security: Constant encryption obfuscation can make it harder for attackers to reverse engineer the code and find vulnerabilities to exploit.

  • Resistance to tampering: The encrypted constants are made resistant to tampering, and can detect when they have been modified and prevent the program from running.

Before Obfuscation:

        public static void Main(string[] args) {
          int i, sum = 0, n;
          Console.Write("Enter the Nth Number : ");
          n = int.Parse(Console.ReadLine());
          for (i = 0; i <= n; i++) {
            sum = sum + i;
          }
          Console.WriteLine("\nSum of N Numbers : " + sum);
          Console.ReadLine();
        }

After Obfuscation:

       public static void Main(string[] args) {
          int i, sum = 0, n;
          Console.Write(().());
          n = int.Parse(Console.ReadLine());
          for (i = 0; i <= n; i++) {
            sum = sum + i;
          }
          Console.WriteLine(().() + sum);
          Console.ReadLine();
        }

Last updated