For license keys, you can use public key encryption. That way, you can insert the private key into the software and encrypt the string that will mean something for your software (for example, what features of your software are licensed). Or you can insert an audience and give the program a line with a special value and sign it with your private key. The software can then verify that the signature is valid.
edit: labratmatt was faster with public-private key response :)
Obviously, the second part of your protection will require solving the problem with the failure and debugging of your software (this is how crackers check your software and try to bypass the protection using a patch, or they try to figure out how they can make a serial). This part is actually much more complicated and includes methods such as encrypting the entire executable file and transferring it inside the bootloader, which decrypts it at run time. The loader can also use various methods to detect the presence of debuggers.
edit:. Since you mentioned that the application is written in JAVA, this encryption and packaging step is even more important because JAVA can be easily decompiled into a form that is very understandable to humans. There are "obfuscator" programs that handle classes, so decompilers cannot generate readable code, but cracking it is still much easier than cracking something compiled for machine code.
If you do not want to spend time developing your own protection, you can also use one of the commercial protection programs. There are quite a lot of them, and they offer many protection schemes (keys, temporary licenses, ...)
Many commercial programs use such packages as FlexNet, HASP, Wibu-key
Jaka
source share