Original: http://blog.csdn.net/eagleking012/article/details/7099900
Usually we have contact with the software registration, enter the serial number, activation code, registration code, Authorization code, for these character codes exactly what the meaning of what is not understood, but in general, these character codes have a few features:
1, uniqueness, is definitely a unique serial number, otherwise there will be abuse problems.
2, encryption, is sure to be encrypted or chaotic, to prevent you to generate serial numbers themselves.
3, decryption, the software itself can certainly be decrypted, otherwise it could not verify the legitimacy.
4, readability, serial numbers are generally more standard, convenient to write and memory, so generally are numbers and letters.
How are these characteristics guaranteed?
1, uniqueness, we can refer to some dynamic factors, such as time, IP, serial number and other information, which ensures the uniqueness of the software environment.
2, encryption, there are many ways, you can use DES, AES symmetric encryption, you can also use RSA for asymmetric encryption.
3, decryption, this time can not be encrypted with MD5, otherwise the information in the serial number is irreversible, the general software and registration code are separate, the software in advance set the key can be decrypted.
4, readability, you can use the hex algorithm to convert the string to a letter.
The first three features have many ways to refer to, the 4th is simple, but for beginners may not understand, the following gives a simple example:
[Java]View Plaincopyprint?
- /**
- * Byte turn hash
- * @param b
- * @return
- */
- Public static String Byte2hex (byte[] b) {
- String hs = "";
- String stmp = "";
- For (int n = 0; n < b.length; n++) {
- Stmp = Integer.tohexstring (B[n] & 0xFF);
- if (stmp.length () = = 1)
- HS + = ("0" + stmp);
- Else
- HS + = STMP;
- }
- return Hs.touppercase ();
- }
- /**
- * Hashi Byte
- * @param b
- * @return
- */
- Public static byte[] Hex2byte (byte[] b) {
- if ((b.length% 2)! = 0)
- throw New IllegalArgumentException ("length is not even");
- byte[] B2 = new byte[b.length/ 2];
- For (int n = 0; n < b.length; n + = 2) {
- String item = new String (b, N, 2);
- B2[n/ 2] = (byte) integer.parseint (item, 16);
- }
- return B2;
- }
How to generate registered serial numbers in Java