Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for unique CD-KEY generation with validation

I am trying to create a unique CD-KEY to put in our product's box, just like a normal CD-KEY found in standard software boxes that users use to register the product.

However we are not selling software, we are selling DNA collection kit for criminal and medical purposes. Users will receive a saliva collection kit by mail with the CD-KEY on it and they will use that CD-KEY to create an account on our website and get their results. The results from the test will be linked to the CD-KEY. This is the only way that we will have to link the results to the patients. It is therefore important that it does not fail :)

One of the requirements would be that the list of CD-KEYs must be sufficiently "spread" apart so that there is no possibility of someone entering an incorrect CD-KEY and still having it approved for someone else kit, thereby mixing up two kits. That could cost us thousands of dollars in liability.

For example, it cannot be a incremental sequence of numbers such as
00001
00002
00003
...
The reason is that if someone receives the kit 00002, but registers it as 000003 by accident, then his results will be matched to someone else. So it must be like credit card numbers... Unless a valid sequence is entered, your chances of randomly hitting a valid number is 1 in a million...

Also, we are selling over 50,000 kits annually to various providers (who will generate their own CD-KEYS using our algorithm) so we cannot maintain a list of all previously issued CD-KEYS to check for duplicate. The algorithm must generate unique CD-KEYs.

We also require the ability to verify that the CD-KEY is valid using a quick check algorithm, so that we can inform the user if the code he enters is invalid. This leaves out many hashing or MD5 algorithms I believe. And it cannot be a 128 bit because, who would take that time to type it out on the computer screen?

So far this is what I was thinking the final CD-KEY structure would look like

(4 char product code) - (4 char reseller code) - (12 char unique, verifiable CD-KEY)

Ex. 384A - GTLD - {4565 - FR54 - EDF3}


To insure the uniqueness of the KEYS, I could include the current date (20090521) as part of the source. We wont generate unique keys more than once a week, so this value changes often enough for the purpose of unique initial value.

What possible algorithm can I use to generate the unique keys?

like image 307
Anon21 Avatar asked May 21 '09 10:05

Anon21


3 Answers

Create the strings <providername>000001, <providername>000002, etc. or whatever and encrypt them with a public key, and that's your "CD-KEY" that the user enters. Decrypt the CD-KEY with the private key and validate that when decrypted you get a valid string with a valid provider name.

like image 136
Die in Sente Avatar answered Nov 15 '22 07:11

Die in Sente


Credit Card numbers use the Luhn algorithm you might want to look at something similar to that.

like image 40
Tom Avatar answered Nov 15 '22 07:11

Tom


I use SeriousBit Ellipter link for software protection but I don't see any reason you could generate a group of unique keys each week and us the library to verify the key validity when entered into your web site. You can also encode optional services into the key allow you to control how the sample is processed from the key (that's if you have different service levels).

As it uses an encrypted method of key generation in the first place and it's relatively cheap, it's certainly worth a look I would say.

like image 36
Lazarus Avatar answered Nov 15 '22 05:11

Lazarus