At least in a typical public key encryption algorithm (for example, RSA), in fact, there is no significant difference between public and private keys. When you create keys, you get two keys. You keep one private and publish the other, but it doesn’t matter which one you publish and which one you save.
Everything that you encrypt with one key can be decrypted with another key. For ordinary purposes, you publish one key that allows anyone to encrypt what you can decrypt. From a technical point of view, the opposite works fine: if you encrypt something with your private key, anyone with a public key can decrypt it. This is usually used for things like signing verification (i.e. anyone with a public key can verify that the signature should have been created using the private key). Usually you want to use separate key pairs for encryption and signing.
For your case, it opens some question that you really are going to execute. You can, of course, encrypt some data necessary for using the program, so the user needs a key to decrypt and use the program, but if the user is ready to provide a copy of the code to an unauthorized person, they probably will not hesitate to give a copy of the key to them. Thus, even though encryption / decryption will do the job, it is unlikely to provide real protection.
A more typical licensing scheme is tied to a specific IP address, so you do something like encrypt the IP address, and then use the result as a key to decrypt the data needed to use the program. If the IP address is incorrect, the data is not decrypted correctly and the program does not work. As long as the user has a static IP address, this may work well, but will cause problems with DHCP.
My immediate advice would simply not do this at all. If you insist on it anyway, don't do it yourself - get something like FlexNet to handle for you. You are better off without it, but at least in this way you will get something similar, and you will not spend time and effort on this that could be aimed at improving goals, such as improving your software.
Jerry Coffin
source share