Some notes on creating your own license keys

If you have to make your own license keys i.e.

ABCDE-ABCDE-ABCDE-ABC1Z-A32DE

Here's some thoughts/ideas for things you can do to break up the key space a little so people can not easily brute-force your keys by fiddliing just a couple of numbers.

  • Select a range of numbers and letters that can be directly mapped to 32 values (10 digits and 22 alpha maybe?).
  • Know your maths.. creating helper classes for unpacking and packing bytes will help.
  • In this example you could carry 125bits (15 bytes and just over a nibble ;o) ... or 13 bytes + CRC16 (or Maybe an Adler16).
  • Use lookup tables to translate sequential values into pseudo-random values.
  • Break any multi-byte values up into individual bytes, stuff em around your payload of bytes in non-sequential offsets.
  • Calculate the CRC for your payload and include it as part of the key's data, verify it when you're decoding.
  • You can use structs with a sequential layout and a packing of 1 to define your structure...
  • Use Marshal.Copy etc. methods to copy between the struct and a byte array.
  • Remap individual bits in the overall payload.


The last one is something that works really well... it's hard
to avoid certain digits "sticking" when generating sequential keys
no matter what you do... but if you remap the individual bits of a
15 byte array (i.e. using a lookup table containing 120 indexes)
you end up with very unique looking keys that have no sequential behaviour to them (especially if you redistribute the bits of the CRC into all the bytes of the key, which in turn are repacked into 5 bit letters).
Written on March 28, 2007