Click here to Skip to main content
15,400,390 members
Articles / Programming Languages / C++
Posted 7 Mar 2014


53 bookmarked

License Key Generation

Rate me:
Please Sign up or sign in to vote.
4.60/5 (9 votes)
7 Mar 2014CPOL2 min read
This is an alternative for "License Key Generation"


The set of sources for automate generation of license keys for software products, allows using string templates of keys with set of required key tokens, checksum values for determining authenticity of generated keys and random data for security reasons.


For generation of license key, it is needed to create a string of license template and add to each token of template initial value. Fields in license key template sting follow sequentially and marked by any choose symbol, as 'n', 'f', 'k' and so on. It is demonstrated in the screenshot of FullTest mode of demo program.


The key fields represent random data and checksums (that are built in library), number of products or article, parts of serial number, version of product, type of used licensing, date of license issue and duration of it, number of allowed runs or views, license expiration date, number of licensed workstations, comment to license, program runs options, etc.

Using the Code

This example shows how simple automate generation of license keys in program:

GenerateKey    gkey;
gkey.AddToken(0, 'p', NUMBER, string(_T("6E")));
gkey.AddToken(0, '0', CHARACTER, string(_T("EOD")));
gkey.AddToken(0, '1', NUMBER, string(_T("1F5")));
gkey.AddToken(0, 'v', NUMBER, string(_T("1")));
gkey.AddToken(0, 's', NUMBER, string(_T("15")));
gkey.AddToken(0, 'r', NUMBER, string(_T("0")));
finalkey = gkey.GetLicenseKey();

Points of Interest

One point as to me said, first readers of this article is really exists – why above example is hanging, when I compile and run it ? The answer also really exists – it's with mistake by name of Apple's double fail goto – so, way of goto is to repair it, that's code will work on you handmade version.

I've done it, as I myself thinking without ideal – so shortly, added few classes, few methods, few fields, some fastcall methods for harding disassembly and antidebuging breakpoints. Now I hope, that no one hacker in the world (source not provided) will hack this code – and I'm glad to present real working, but still battle prototype of license key registration-disassembly program.

For readers, that to them won't stay doubt about source, from (by secret – password to this program is) 91 methods supplied to article – something really could.


This is port to C++ original article License Key Generation by Donsw realised on C#, so detailed explanation of algorithms and library files with documentation possible find in it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer LLC "AMS"
Russian Federation Russian Federation
In 1991 year has received senior secondary education and entered in Moscow Economic-statistical Institute, by faculty of Supply mathematics, has studied to 2-nd course with high progress, and left it by own will.

With 1994-1996 years - serviced in army (navy fleet, now sailor of a stock).

Since 1999 year has begun my labour career, with job of computer operator, in department of computer maintenance developing learn-methodical documentation.

Single, on religion - atheist.

Comments and Discussions

SuggestionSource Code Link Not Working..... Pin
Gary Noble7-Mar-14 6:04
MemberGary Noble7-Mar-14 6:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.