Table of Contents

Introduction

This article is devoted to the development of the key licensing system for the applications. In the theoretical part of the article, we will examine the cryptography methods, which can be used while implementing the licensing system. Also, we will discuss all pros and cons of these methods and select the possible ones for using in the application. In the practical part of the article, we will provide the implementation of the simplest licensing system, which guaranties the protection from cracking even if a hacker knows the source code of an algorithm.

Types of Algorithms

The cryptographic algorithm, also called cipher, is a mathematical function used for encryption and decryption. Usually, these are two interconnected functions: one is used for encryption, another is for decryption.

If the reliability of the algorithm is based on keeping the algorithm itself in secret, then this algorithm is limited. Limited algorithms do not correspond to the nowadays standards and represent only the historical value.

The modern cryptography solves these problems with the help of the key. The key can be of any value selected from a wide range of values. The set of possible keys is called the key space.

There are two main types of algorithms based on the key usage: symmetric-key algorithm and algorithm with the public key.

Symmetric-key algorithms, sometimes called the conditional algorithms, are the algorithms where the encryption key can be calculated by the decryption key and vice versa. The encryption and decryption keys are the same in most symmetric-key algorithms. These algorithms, also called one-key or secret-key algorithms, require that the sender and the recipient reconcile the used key before the beginning of the secure message exchange. The safety of the symmetric-key algorithms is defined by the key. The key disclosure means that anyone can encrypt and decrypt messages. The key must be kept in secret as long as the transmitted messages should be secret.

Algorithms with the public key, also called asymmetric-key algorithms, are developed in a way that the key used for the encryption differs from that for decryption. Moreover, the decryption key can't be calculated by the encryption key (at least, during the reasonable period of time). These algorithms are called “algorithms with the public key” because the encryption key can be open: anyone can use the encryption key for the encryption of the message but only one concrete person can decrypt the message with the corresponding decryption key. In these systems, the encryption key is often called the public key and the decryption key is called the private key. The private key is sometimes called the secret key.

It is obvious that the only type of the algorithm which suits us is the algorithm with the public key because we have to store the key in the program for the authentication of the entered serial key. When choosing these algorithms, we have the guarantee that the intruder, having the public key and the source code of the algorithm, won't be able to make the key generator and create serial keys for another program copies.

There are many computer algorithms. The following three algorithms are most frequently used:

DES (Data Encryption Standard) is the most popular computer encryption algorithm. It is the American and international standard. It is the symmetric-key algorithm where one and the same key is used for encryption and decryption.

RSA (which stands for Rivest, Shamir and Adleman who first publicly described it) is the most popular algorithm with the public key. It is used both for the encryption and for digital signature.

DSA (Digital Signature Algorithm, is used as the part of the Digital Signature Standard) is another algorithm with the public key. It is used only for the digital signature and can’t be used for the encryption.

DES does not suit us because it is the symmetric-key algorithm.

Two algorithms are left: RSA and DSA. It is easy to choose between them if we look at the structure of the work of these algorithms.

RSA uses the public key for the creation of the cipher text from the source text. We don't need it as it is supposed that we create and send keys and they will be decrypted and compared with the source value on the client side. As it was mentioned above, we can use only the public key on the client side in order not to compromise the licensing system.

Now some words about the work of DSA. Using the source text, DSA calculates the hash code and then “decrypts” it using the private key and receives the required serial key. It “encrypts” the received value on the client side and receives the hash code. Then it calculates the hash code from the source text in the usual way and compares two values. If these values coincide, then the serial key is valid.

The Crypto++® Library contains the implementation of many algorithms. I used this library in the example. For more information, see http://www.cryptopp.com/.

Hardware Serial Key

We need to have the unique identifier of the computer in order to make sure that our serial key is used on the computer where we granted a license. There are many methods of its obtaining. But we chose HardDisk Serial Key for this case. It has a rather readable form and small size, but the probability of collisions is very low.

Hi Sergii. Thanks for this informative article. Really appreciate it. I would like to find out if is it possible to hack the software implementing this algorithm by shipping the software with the public key replaced with a copy of the hacker's self-generated public key. That way, when a user sends the harddrive serial key to the hacker, he can generate the license.dat file using his private key since the public key shipped with the software to the user is the public key pair generated by the hacker. Am I right to say so? This is partly due to the fact that your code load the public key from a file. As far as I know the public key should be at least hard-coded in the software right?

First, let me appreciate your idea and helpful source code about the “Implementation of The Licensing System for a Software Product”.
I want to ask for your help and guidance about a problem that I am facing in developing software which needs self-decryption through runtime. I want to keep my private key secure within the source code. What is the best solution to keep this key secure and out of rich? I think, if I want to keep the key in resource, it would be extractable by hackers. What is your solution?

This is very complicated task and it requires a lot of research - first of all I wouldn't recommend you to store PRIVATE key in the code anyhow. You can use reverse scheme and use private key for crypting and public for decrypting ( this is described in the article ) and you'll be able to save public key, but this all just sounds bad for me.
Thanks to the internet we can find a lot of info - and first you probably want to look at is Polymorphic Encryption Methods with it's key techniques such as saving a static key, or saving the key that is changing all the time, or еру key that has external dependencies or even without a key - using just bit operations. Hope you'll find there answer you need. Good luck )

Have you given any thought to a Timed License such as one the lasts for seven days. I believe you would need to hide something on the computer with the start or expirey date. However with the later versions of windows it is getting more and more difficult to hide a file or something in the registry, that can't be easily found and deleted.

I like the topic very much and I thought you started well with explaning at the beginning. Unfortunately you stop explaining once the 1st line of code appears.
You could for example explain the steps in your nice looking scheme diagram and also add more explanation to the code and why you did what you did. After all, an expert in the field doesn't need to read your article, us novices do

How to protect the client AND the license manager from being hacked to easily would also be an important chapter to add - methinks.

However I would caution the readers that this is only a start. Any successful licencing system has to protect the client application from tampering otherwise it would take 5 minutes to remove the licence check for even a novice hacker.

I agree. I've been in software development for well over 10 years now and I have come to realize that (software) protection doesn't work. It just keeps honest people honest.
Any determined hacker can decompile your application and remove the triggers. Apps like Windows and Photoshop, games like GTA and COD:MW2, machines like Xbox and Nintendo DS, carriers like DVD and BluRay, ... everything has been cracked.

Great work explaining a basic licensing scheme.
Do you have any suggestions on revoking a license, protect it from spoofing (if a user can spoof the hardware information from an authorized user he could use the same license key)?

This function reads attributes using S.M.A.R.T. technology. So either your drives do not support it (maybe some spesific model) or you do not have rights to read it. Please turn off UAC and try - it should work fine. If it doesn't please tell the LOC where you get FALSE.