<p>My company is looking to start distributing some software we developed and would like to be able to let people try the software out before buying.  We'd also like to make sure it can't be copied and distributed to our customers' customers.</p>

<p>One model we've seen is tying a license to a MAC address so the software will only work on one machine.</p>

<p>What I'm wondering is, what's a good way to generate a license key with different information embedded in it such as license expiration date, MAC address, and different software restrictions?</p>

[{'answer_id': 49666, 'author': 'Matt Sheppard', 'author_id': 797, 'author_profile': 'https://Stackoverflow.com/users/797', 'pm_score': 4, 'selected': True, 'text': "<p>I'd suggest you take the pieces of information you want in the key, and hash it with md5, and then just take the first X characters (where X is a key length you think is manageable).</p>\n\n<p>Cryptographically, it's far from perfect, but this is the sort of area where you want to put in the minimum amount of effort which will stop a casual attacker - anything more quickly becomes a black hole.</p>\n\n<p>Oh, I should also point out, you will want to provide the expiration date (and any other information you might want to read out yourself) in plain text (or slightly obfuscated) as part of the key as well if you go down this path - The md5 is just to stop the end user from changing he expiration date to extend the license.</p>\n\n<p>The easiest thing would be a key file like this...</p>\n\n<pre><code># License key for XYZZY\nexpiry-date=2009-01-01\nother-info=blah\nkey=[md5 has of MAC address, expiry date, other-info]\n</code></pre>\n"}, {'answer_id': 49672, 'author': 'JohnV', 'author_id': 4589, 'author_profile': 'https://Stackoverflow.com/users/4589', 'pm_score': 0, 'selected': False, 'text': "<p>It is difficult to provide a good answer without knowing anything about your product and customers. For enterprise software sold to technical people you can use a fairly complex licensing system and they'll figure it out. For consumer software sold to the barely computer-literate, you need a much simpler system.</p>\n\n<p>In general, I've adopted the practice of making a very simple system that keeps the honest people honest. Anyone who really wants to steal your software will find a way around any DRM system. </p>\n\n<p>In the past I've used Armadillo (now Software Passport) for C++ projects. I'm currently using XHEO for C# projects.</p>\n"}, {'answer_id': 49674, 'author': 'Biri', 'author_id': 968, 'author_profile': 'https://Stackoverflow.com/users/968', 'pm_score': 1, 'selected': False, 'text': '<p>We keep it simple: store every license data to an XML (easy to read and manage), create a hash of the whole XML and then crypt it with a utility (also own and simple).</p>\n\n<p>This is also far from perfect, but it can hold for some time.</p>\n'}, {'answer_id': 49681, 'author': 'titanae', 'author_id': 2387, 'author_profile': 'https://Stackoverflow.com/users/2387', 'pm_score': 1, 'selected': False, 'text': "<p>Almost every commercial license system has been cracked, we have used many over the years all eventually get cracked, the general rule is write your own, change it every release, once your happy try to crack it yourself. </p>\n\n<p>Nothing is really secure, ultimately look at the big players Microsoft etc, they go with the model honest people will pay and other will copy, don't put too much effort into it.</p>\n\n<p>If you application is worth paying money for people will.</p>\n"}, {'answer_id': 49690, 'author': 'sven', 'author_id': 46, 'author_profile': 'https://Stackoverflow.com/users/46', 'pm_score': 2, 'selected': False, 'text': '<p>The company I worked for actually used a <a href="http://en.wikipedia.org/wiki/Dongle" rel="nofollow noreferrer">usb dongle</a>. This was handy because:</p>\n\n<ul>\n<li>Our software was also installed on that USB Stick</li>\n<li>The program would only run if it found the (unique) hardware key (any standard USB key has that, so you don\'t have to buy something special, any stick will do)</li>\n<li>it was not restricted to a computer, but could be installed on another system if desired</li>\n</ul>\n\n<p>I know most people don\'t like dongles, but in this case it was quite handy as it was actually used for a special purpose <em>media player</em> that we also delivered, the USB keys could thus be used as a demo on <em>any</em> pc, but also, and without any modifications, be used in the real application (ie the real players), once the client was satisfied</p>\n'}, {'answer_id': 49726, 'author': 'Jason Cohen', 'author_id': 4926, 'author_profile': 'https://Stackoverflow.com/users/4926', 'pm_score': 3, 'selected': False, 'text': '<p>We\'ve used the following algorithm at <a href="http://smartbear.com" rel="noreferrer">my company</a> for years without a single incident.</p>\n\n<ol>\n<li>Decide the fields you want in the code.  Bit-pack as much as possible.  For example, dates could be "number of days since 2007," and then you can get away with 16-bits.</li>\n<li>Add an extra "checksum" field.  (You\'ll see why in a second.)  The value of this field is a checksum of the packed bytes from the other fields.  We use "first 32 bits from MD5."</li>\n<li>Encrypt everything using <a href="http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm" rel="noreferrer">TEA</a>.  For the key, use something that identifies the customer (e.g. company name + personal email address), that way if someone wants to post a key on the interweb they have to include their own contact info in plain text.</li>\n<li>Convert hex to a string in some sensible way.  You can do straight hex digits but some people like to pick a different set of 16 characters to make it less obvious.  Also include dashes or something regularly so it\'s easier to read it over the phone.</li>\n</ol>\n\n<p>To decrypt, convert hex to string and decrypt with TEA.  But then there\'s this extra step: Compute your own checksum of the fields (ignoring the checksum field) and compare to the given checksum.  <em>This is the step that ensures no one tampered with the key</em>.</p>\n\n<p>The reason is that TEA mixes the bits completely, so if even one bit is changed, all other bits are equally likely to change during TEA decryption, therefore the checksum will not pass.</p>\n\n<p>Is this hackable?  Of course!  Almost everything is, but this is tight enough and simple to implement.</p>\n\n<p>If tying to contact information is not sufficient, then include a field for "Node ID" and lock it to MAC address or somesuch as you suggest.</p>\n'}, {'answer_id': 49774, 'author': 'Peter', 'author_id': 5189, 'author_profile': 'https://Stackoverflow.com/users/5189', 'pm_score': 0, 'selected': False, 'text': '<p>If your product requires the use of the internet, then you can generate a unique id for the machine and use that to check with a license web service.</p>\n\n<p>If it does not, I think going with a commercial product is the way to go.  Yes, they can be hacked, but for the person who is absolutely determined to hack it, it is unlikely they ever would have paid.</p>\n\n<p>We have used: <a href="http://www.aspack.com/asprotect.aspx" rel="nofollow noreferrer">http://www.aspack.com/asprotect.aspx</a></p>\n\n<p>We also use a function call in their sdk product that gives us a unique id for a machine.</p>\n\n<p>Good company although clearly not native English speakers since their first product was called "AsPack".</p>\n'}, {'answer_id': 49784, 'author': 'Larry Gritz', 'author_id': 3832, 'author_profile': 'https://Stackoverflow.com/users/3832', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve used both FLEXlm from Macrovision (formerly Globetrotter) and the newer RLM from Reprise Software (as I understand, written by FlexLM\'s original authors).  Both can key off either the MAC address or a physical dongle, can be either node-locked (tied to one machine only) or "floating" (any authorized machine on the network can get a license doled out by a central license server, up to a maximum number of simultaneously checked-out copies determined by how much they\'ve paid for).  There are a variety of flexible ways to set it up, including expiration dates, individual sub-licensed features, etc.  Integration into an application is not very difficult.  These are just the two I\'ve used, I\'m sure there are others that do the job just as well.</p>\n\n<p>These programs are easily cracked, meaning that there are known exploits that let people either bypass the security of your application that uses them, either by cutting their own licenses to spoof the license server, or by merely patching your binary to bypass the license check (essentially replacing the subroutine call to their library with code that just says "return \'true\'".  It\'s more complicated than that, but that\'s what it mostly boils down to.  You\'ll see cracked versions of your product posted to various Warez sites.  It can be very frustrating and demoralizing, all the more so because they\'re often interested in cracking for cracking sake, and don\'t even have any use for your product or knowledge of what to do with it.  (This is obvious if you have a sufficiently specialized program.)</p>\n\n<p>Because of this, some people will say you should write your own, maybe even change the encryption scheme frequently.  But I disagree.  It\'s true that rolling your own means that known exploits against FLEXlm or RLM won\'t instantly work for your application.  However, unless you are a total expert on this kind of security (which clearly you aren\'t or you wouldn\'t be asking the question), it\'s highly likely that in your inexperience you will end up writing a much less secure and more crackable scheme than the market leaders (weak as they may be).</p>\n\n<p>The other reason not to roll your own is simply that it\'s an endless cat and mouse game.  It\'s better for your customers and your sales to put minimal effort into license security and spend that time debugging or adding features.   You need to come to grips with the licensing scheme as merely "keeping honest people honest", but not preventing determined cracking.  Accept that the crackers wouldn\'t have paid for the software anyway.</p>\n\n<p>Not everybody can take this kind of zen attitude.  Some people can\'t sleep at night knowing that somebody somewhere is getting something for nothing.  But try to learn to deal with it.  You can\'t stop the pirates, but you can balance your time/effort/expense trying to stop all piracy versus making your product better for users.  Remember, sometimes the most pirated applications are also the most popular and profitable.  Good luck and sleep well.</p>\n'}, {'answer_id': 1495316, 'author': 'Duncan Bayne', 'author_id': 181452, 'author_profile': 'https://Stackoverflow.com/users/181452', 'pm_score': 2, 'selected': False, 'text': '<p>Don\'t use MAC addresses.  On some hardware we\'ve tested - in particular some IBM Thinkpads - the MAC address can change on a restart.  We didn\'t bother investigating <em>why</em> this was, but we learned quite early during our research not to rely on it.</p>\n\n<p>Obligatory disclaimer &amp; plug: the company I co-founded produces the <a href="https://cobalt.offbyzero.com/" rel="nofollow noreferrer">OffByZero Cobalt licensing solution</a>.  So it probably won\'t surprise you to hear that I recommend outsourcing your licensing, &amp; focusing on your core competencies.</p>\n\n<p>Seriously, this stuff is quite tricky to get right, &amp; the consequences of getting it wrong could be quite bad.  If you\'re low-volume high-price a few pirated copies could seriously dent your revenue, &amp; if you\'re high-volume low-price then there\'s incentive for warez d00dz to crack your software for fun &amp; reputation.</p>\n\n<p>One thing to bear in mind is that there is no such thing as truly crack-proof licensing; once someone has your byte-code on their hardware, you have given away the ability to completely control what they do with it. </p>\n\n<p>What a good licensing system does is raise the bar sufficiently high that purchasing your software is a better option - especially with the rise in malware-infected pirated software.  We recommend you take a number of measures towards securing your application:</p>\n\n<ul>\n<li>get a good third-party licensing system</li>\n<li>pepper your code with scope-contained checks (e.g. no one global variable like fIsLicensed, don\'t check the status of a feature near the code that implements the feature)</li>\n<li>employ serious obfuscation in the case of .NET or Java code</li>\n</ul>\n'}, {'answer_id': 2000702, 'author': 'Csharprules', 'author_id': 243317, 'author_profile': 'https://Stackoverflow.com/users/243317', 'pm_score': 1, 'selected': False, 'text': "<p>I've used a number of different products that do the license generation and have created my own solution but it comes down to what will give you the most flexibility now and down the road.</p>\n\n<p>Topics that you should focus on for generating your own license keys are...</p>\n\n<p>HEX formating,  elliptic curve cryptography, and any of the algorithms for encryption such as AES/Rijndael, DES, Blowfish, etc.  These are great for creating license keys.</p>\n\n<p>Of course it isn't enough to have a key you also need to associate it to a product and program the application to lock down based on a key system you've created.</p>\n\n<p>I have messed around with creating my own solution but in the end when it came down to making money with the software I had to cave and get a commercial solution that would save me time in generating keys and managing my product line...  </p>\n\n<p>My favorite so far has been License Vault from SpearmanTech but I've also tried FlexNet (costly), XHEO (way too much programming required), and SeriousBit Ellipter.</p>\n\n<p>I chose the License Vault product in the end because I would get it for much cheaper than the others and it simply had more to offer me as we do most of our work in .NET 3.5.</p>\n"}]
['https://Stackoverflow.com/questions/49662', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5106/']