You can generate license files Public-Private key Cryptography, and using RSA. Please look at this library, you can found this useful. http://afewguyscoding.com/page/2/ This library people have also done survey, which will give you idea that how good this method works.
There is another github project using similar approach. Visit https://github.com/starschema/slm4j