How to generate registered serial numbers in Java

Source: Internet
Author: User
Tags asymmetric encryption

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?
  1. /**
  2. * Byte turn hash
  3. * @param b
  4. * @return
  5. */
  6. Public static String Byte2hex (byte[] b) {
  7. String hs = "";
  8. String stmp = "";
  9. For (int n = 0; n < b.length; n++) {
  10. Stmp = Integer.tohexstring (B[n] & 0xFF);
  11. if (stmp.length () = = 1)
  12. HS + = ("0" + stmp);
  13. Else
  14. HS + = STMP;
  15. }
  16. return Hs.touppercase ();
  17. }
  18. /**
  19. * Hashi Byte
  20. * @param b
  21. * @return
  22. */
  23. Public static byte[] Hex2byte (byte[] b) {
  24. if ((b.length% 2)! = 0)
  25. throw New IllegalArgumentException ("length is not even");
  26. byte[] B2 = new byte[b.length/ 2];
  27. For (int n = 0; n < b.length; n + = 2) {
  28. String item = new String (b, N, 2);
  29. B2[n/ 2] = (byte) integer.parseint (item, 16);
  30. }
  31. return B2;
  32. }

How to generate registered serial numbers in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.