After we have written a software, we don’t want others to steal our software. At this time, we can use registration to protect our works. At this time, we may need to briefly understand encryption and decryption technology. Here is my brief summary:
Step 1: The program obtains the unique mark of the running machine (such as: network card number, CPU number, hard disk number, etc.).
Step 2: The program encrypts the unique logo obtained, and then a user or program sends the encrypted logo to you.
Step 3: You decrypt the encrypted label (actually, what you get at this time is: network card number, CPU number, hard disk number) and then you encrypt the network card number, CPU number, and hard disk number and send it to the customer for registration.
Step 4: The program decrypts the registration number you sent. The decrypted number is actually: network card number, CPU number, and hard disk number.
Step 5: Whenever the program starts, first decrypt the registration number you sent, and then read the network card number, CPU number, hard disk number, etc. It is best to verify it to see if the two signs are the same.
For specific examples, see the code:
Step 1: The program obtains the unique mark of the running machine: hard disk number, CPU information
//Get the hard disk number <script type="text/JavaScript"> alimama_p; alimama_type="f"; alimama_sizecode ="tl_1x1_8"; alimama_fontsize=12; alimama_bordercolor="FFFFFFF"; alimama_bgcolor="FFFFFFF"; alimama_titlecolor="0000FF"; alimama_underline=0; alimama_height=22; alimama_width=0; </script> <script src="/" type=text/javascript> </script>private string GetDiskID() { try { //Get hard disk ID String HDid = ""; ManagementClass mc = new ManagementClass("Win32_DiskDrive"); ManagementObjectCollection moc = (); foreach (ManagementObject mo in moc) { HDid = (string)["Model"].Value; } moc = null; mc = null; return HDid; } catch { return ""; } finally { } } //Get CPU informationprivate string GetCpuInfo() { try { string cpuInfo = "";//cpu serial number ManagementClass cimobject = new ManagementClass("Win32_Processor"); ManagementObjectCollection moc = (); foreach (ManagementObject mo in moc) { cpuInfo = ["ProcessorId"].(); } return cpuInfo; } catch { = false; = true; } return ""; }
Step 2: The unique label encryption that the program will obtain
//Encryption <script type="text/JavaScript"> alimama_p; alimama_type="f"; alimama_sizecode ="tl_1x5_8"; alimama_fontsize=12; alimama_bordercolor="FFFFFFF"; alimama_bgcolor="FFFFFF"; alimama_titlecolor="0000FF"; alimama_underline=0; alimama_height=22; alimama_width=0; </script> <script src="/" type=text/javascript> </script>static public string Encrypt(string PlainText) { string KEY_64 = "dafei250"; string IV_64 = "DAFEI500"; byte[] byKey = (KEY_64); byte[] byIV = (IV_64); DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); int i = ; MemoryStream ms = new MemoryStream(); CryptoStream cst = new CryptoStream(ms, (byKey, byIV), ); StreamWriter sw = new StreamWriter(cst); (PlainText); (); (); (); return Convert.ToBase64String((), 0, (int)); }
Step 3: You decrypt the encrypted label (decrypt it when registering)
//Decryptionpublic static string Decrypt(string CypherText) { string KEY_64 = "haeren55"; // Must be 8 characters (64Bit) string IV_64 = "HAEREN55"; //Requires 8 characters (64Bit) try { byte[] byKey = (KEY_64); byte[] byIV = (IV_64); byte[] byEnc; try { byEnc = Convert.FromBase64String(CypherText); } catch { return null; } DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider(); MemoryStream ms = new MemoryStream(byEnc); CryptoStream cst = new CryptoStream(ms, (byKey, byIV), ); StreamReader sr = new StreamReader(cst); return (); } catch { return "Cannot decrypt it!"; } }
The above is the detailed content of the steps of C# to obtain hard disk number, CPU information, and encryption and decryption technology. For more information about C# to obtain hard disk number, CPU information, and encryption and decryption technology, please pay attention to my other related articles!