General introduction of software encryption software registration technology

Source: Internet
Author: User
Tags foreach decrypt flush

After we write a software, we do not want people to steal our software, at this time we can register to protect our work. At this point we may need to understand the encryption and decryption technology, here is my brief summary:

The first step: The program gets the only indication of the running machine (for example: Network card number, CPU number, hard disk number, etc.).

The second step: The program will obtain the only mark encryption, and then a user or program will be encrypted after the logo sent to you.

The third step: you will encrypt the mark after decryption (in fact, this time you get is: Network card number, CPU number, hard disk number) then you will be the network card number, CPU number, hard disk number encryption sent to the customer registration.

Fourth step: The program will send you the registration number to decrypt, after the decryption of the number is actually: Network card number, CPU number, hard drive number.

Fifth step: Whenever the program starts, first decrypt the registration number you send, and then read the network card number, CPU number, hard disk number, etc., it is best to verify, see two signs are the same.

Specific example to see the code:

Step One: The program gets the only indication of the running machine: Hard drive number, CPU information

  1. //Get the hard drive number
  2. private String Getdiskid ()
  3. {
  4. Try
  5. {
  6. Get the hard drive ID
  7. String hdid = "";
  8. ManagementClass mc = New managementclass ("win32_diskdrive");
  9. Managementobjectcollection MOC = MC. GetInstances ();
  10. foreach (ManagementObject mo in MOC)
  11. {
  12. Hdid = (string) mo. properties["Model"]. Value;
  13. }
  14. MOC = null;
  15. MC = NULL;
  16. return Hdid;
  17. }
  18. Catch
  19. {
  20. return "";
  21. }
  22. finally
  23. {
  24. }
  25. }
  26. //Get CPU information
  27. private String Getcpuinfo ()
  28. {
  29. Try
  30. {
  31. string cpuInfo = "";//cpu serial number
  32. ManagementClass cimobject = new managementclass ("Win32_Processor");
  33. Managementobjectcollection MOC = Cimobject. GetInstances ();
  34. foreach (ManagementObject mo in MOC)
  35. {
  36. CpuInfo = mo. properties["Processorid"]. Value.tostring ();
  37. }
  38. return cpuInfo;
  39. }
  40. Catch
  41. {
  42. this. senregeditid.enabled = false;
  43. this. getid.enabled = true;
  44. }
  45. return "";
  46. }

Step Two: The program will get the only indication of encryption

  1. //Encryption
  2. static public string Encrypt (string plaintext)
  3. {
  4. string key_64 = "dafei250";
  5. string iv_64 = "DAFEI500";
  6. byte [] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
  7. byte [] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (iv_64);
  8. DESCryptoServiceProvider CryptoProvider = new descryptoserviceprovider ();
  9. int i = cryptoprovider.keysize;
  10. MemoryStream ms = new MemoryStream ();
  11. CryptoStream CST = new CryptoStream (MS, Cryptoprovider.createencryptor (Bykey, Byiv), CryptoStreamMode.Write) ;
  12. StreamWriter sw = new StreamWriter (CST);
  13. Sw. Write (plaintext);
  14. Sw. Flush ();
  15. Cst. FlushFinalBlock ();
  16. Sw. Flush ();
  17. return Convert.tobase64string (Ms. GetBuffer (), 0, (int) Ms. Length);
  18. }

Step three: You will decrypt the encrypted logo (when you sign up)

  1. //Decryption
  2. Public static String Decrypt (String cyphertext)
  3. {
  4. string key_64 = "haeren55"; //Must be 8 characters (64Bit)
  5. string  iv_64 = "HAEREN55"; //Must be 8 characters (64Bit)
  6. Try
  7. {
  8. byte [] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
  9. byte [] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (iv_64);
  10. byte [] Byenc;
  11. Try
  12. {
  13. Byenc = convert.frombase64string (cyphertext);
  14. }
  15. Catch
  16. {
  17. return null;
  18. }
  19. DESCryptoServiceProvider CryptoProvider = new descryptoserviceprovider ();
  20. MemoryStream ms = New MemoryStream (BYENC);
  21. CryptoStream CST = new CryptoStream (MS, Cryptoprovider.createdecryptor (Bykey, Byiv), cryptostreammode.read);
  22. StreamReader sr = New StreamReader (CST);
  23. return Sr. ReadToEnd ();
  24. }
  25. Catch { return " cannot decrypt !";}
  26. }

The fourth step fifth step is needless to say specifically. In addition: If you need to reprint, please specify the source: half a cigarette jie. http://blog.csdn.net/gisfarmer/Thank you.

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.