1) Create a License key feature for your application
Ever wanted to add a license key feature to your application ?
It is simple but will take a lot of time from you
Because you need to come up with a good algorithm that will be hard to be broken.
What do you need ?
1) Key Generator.
2) Key and DateValidation function in client application
3) Register the information of client in registry or somewhere on the hard drive so you make sure he already
entered a registration information.
Now it wont be logical to send the product key like that.
Any kid can understand the algorthim here.
So what you can do is replacing each char with another char.
For example :
Original Key : ABCD - EFGH - IJKL - MNOP
Product Key : PLHD - OKGC - JJFB - MIEA
1) Key Generator Function :
I`ll be giving the Create_Key date like : ABCDEFGHIJKLMNOP and it will replace everything and add "-" after each 4 chars
Code:
private string Create_Key(string data)
{
byte[] bytes = Encoding.ASCII.GetBytes(data);
string KEY = string.Empty;
KEY += data[15];
KEY += data[14];
KEY += data[8];
KEY += data[9];
KEY += "-";
KEY += data[6];
KEY += data[11];
KEY += data[4];
KEY += data[12];
KEY += "-";
KEY += data[2];
KEY += data[3];
KEY += data[13];
KEY += data[5];
KEY += "-";
KEY += data[7];
KEY += data[10];
KEY += data[1];
KEY += data[0];
return KEY;
}
In client application the client will provide a product key , you need to follow these steps to ensure that the key is valis
1) Check the prefix of the key
2) If prefix is correct then it is a valid key then lets Check the expiration Date of the key
3) If key is not yet expired then open appliation.
- a) Key Validation Function : [Read Prefix]
The key Validation function will be the same Key Generator function which is >>>Create_Key() ,
Because we are using the same algorthim in key generation process.
Step one : reverse the the product key because we need the original Key to read prefix.
Code:
private string Create_Key(string Product_Key)
{
byte[] bytes = Encoding.ASCII.GetBytes(Product_Key);
string KEY = string.Empty;
KEY += Product_Key[15];
KEY += Product_Key[14];
KEY += Product_Key[8];
KEY += Product_Key[9];
KEY += "-";
KEY += Product_Key[6];
KEY += Product_Key[11];
KEY += Product_Key[4];
KEY += Product_Key[12];
KEY += "-";
KEY += Product_Key[2];
KEY += Product_Key[3];
KEY += Product_Key[13];
KEY += Product_Key[5];
KEY += "-";
KEY += Product_Key[7];
KEY += Product_Key[10];
KEY += Product_Key[1];
KEY += Product_Key[0];
return KEY;
}
Step two :
Create a Bool function to retun the legit status of the key :
private bool validate_key(string key)
{
string[] seperate_filelds = key.Split('-');
int counter=0;
bool is_legit = false;
foreach (string each_field in seperate_filelds)
{
counter++;
// reading the first field which is prefix field
if (counter == 1)
{
if (each_field == "Your_Prefix")
{
is_legit = true;
}
}
else
{ break; }
}
return is_legit;
}
For Detail Reference