Question: How can I create a product key for my C# Application?

I need to create a product (or license) key that I update annually. Additionally I need to create one for trial versions.

> 
> Related:
> 
> 
> * [How do I best obfuscate my C# product license verification code?](https://stackoverflow.com/questions/501988)
> * [How do you protect your software from illegal distribution?](https://stackoverflow.com/questions/109997)
> 
> 
>

Answer: 
I have to admit I'd do something rather insane.

1. Find a CPU bottleneck and extract it to a [P/Invokeable](http://en.wikipedia.org/wiki/Platform_Invocation_Services) DLL file.
2. As a post build action, encrypt part of the DLL file with an XOR
encryption key.
3. Select a public/private key scheme, include public key in the DLL file
4. Arrange so that decrypting the product key and XORing the two
halves together results in the encryption key for the DLL.
5. In the DLL's DllMain code, disable protection (PAGE\_EXECUTE\_READWRITE)
and decrypt it with the key.
6. Make a LicenseCheck() method that makes a sanity check of the
license key and parameters, then checksums entire DLL file, throwing
license violation on either. Oh, and do some other initialization
here.

When they find and remove the LicenseCheck, what fun will follow
when the DLL starts [segmentation faulting](http://en.wikipedia.org/wiki/Segmentation_fault).
The trick is to have an algorithm that only you know (such that it could be decoded at the other end). 

There are simple things like, "Pick a prime number and add a magic number to it"

More convoluted options such as using asymmetric encryption of a set of binary data (that could include a unique identifier, version numbers, etc) and distribute the encrypted data as the key.

Might also be worth reading the responses to [this question](https://stackoverflow.com/questions/404806/pin-generation#404904) as well