1

The user will have to enter a licence key. That key will be writeten somewhere so that on the next application launch, the user won't be needed to insert it again. Let's say that the licence will be kept in a .txt file.

In order to make this aproach more secure, my question is: how could I immediatly embbed that resource in the application after the user writes the key so that the file won't be visible in the app folder?

Or maybe, is there any other way to somehow keep the key in the application after the user writes it and on the next executions, the app will still be able to see it?

The "embed it like a resource" and read it from there the next time thing is just my idea, maybe there are other better ones.

Christopher H.
  • 4,017
  • 2
  • 15
  • 39
bvg
  • 163
  • 12
  • 2
    Your app cannot modify itself. What problem are you trying to solve here? – stuartd Mar 15 '18 at 15:48
  • I want to get rid of the fact that the user will always have his inserted licence available, to see, to manipulate, to share and so on. I want to hide it permanently. – bvg Mar 15 '18 at 15:50
  • 1
    Most developers use the registry for storing this kinda stuff... If the key doesn't exist, prompt for a license key. If it does, check for validity. – Brandon Miller Mar 15 '18 at 15:53
  • Yes, I do that. If there is no licence, there is a licence prompt. If the inserted licence is wrong, the app won't start. I want to avoid the many issues that appear when a correct licence is manually edited afterwards. The licence is kept encripted and the decription algorithm can be mislead by additional stuff written by users afterwards. – bvg Mar 15 '18 at 15:56

1 Answers1

1

Your wants can be fulfilled by easily creating a string variable in My.Settings but as this is a about licensing,use :

 IO.File.WriteAllText(IO.Directory.GetCurrentDirectory + "\license.abc","license string here")

you may even want to encrypt the file,for that :

class Encryptor
{
    public static string Key = "license here";

    public static string Encrypt (string decrypted)
    {
        byte[] textbytes = ASCIIEncoding.ASCII.GetBytes(decrypted);
        AesCryptoServiceProvider endec = new AesCryptoServiceProvider();
        endec.BlockSize = 128;
        endec.KeySize = 256;
        endec.Key = ASCIIEncoding.ASCII.GetBytes(Key);
        endec.Padding = PaddingMode.PKCS7;
        endec.Mode = CipherMode.CBC;
        ICryptoTransform icrypt = endec.CreateEncryptor(endec.Key);
        byte[] enc = icrypt.TransformFinalBlock(textbytes, 0, textbytes.Length);
        icrypt.Dispose();
        return Convert.ToBase64String(enc);
    }

Another bet would be store the license in registry :

 Microsoft.Win32.RegistryKey key;  
 key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("key");  
 key.SetValue("key", "licenseKeyHere");  
 key.Close();  

Your best bet is to let the activation happen online,let it connect to your database over the net and activate.You can go with SQL Server,MySql or other similar products.

And one more thing,as u mentioned in ur qs,u want to embed a file to the app so tht the user can't see it ? Why not, use my 1st/2nd method and finally do this :

 File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.Hidden);
Christopher H.
  • 4,017
  • 2
  • 15
  • 39