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
- //Get the hard drive number
- private String Getdiskid ()
- {
- Try
- {
- Get the hard drive ID
- String hdid = "";
- ManagementClass mc = New managementclass ("win32_diskdrive");
- Managementobjectcollection MOC = MC. GetInstances ();
- foreach (ManagementObject mo in MOC)
- {
- Hdid = (string) mo. properties["Model"]. Value;
- }
- MOC = null;
- MC = NULL;
- return Hdid;
- }
- Catch
- {
- return "";
- }
- finally
- {
- }
- }
- //Get CPU information
- private String Getcpuinfo ()
- {
- Try
- {
- string cpuInfo = "";//cpu serial number
- ManagementClass cimobject = new managementclass ("Win32_Processor");
- Managementobjectcollection MOC = Cimobject. GetInstances ();
- foreach (ManagementObject mo in MOC)
- {
- CpuInfo = mo. properties["Processorid"]. Value.tostring ();
- }
- return cpuInfo;
- }
- Catch
- {
- this. senregeditid.enabled = false;
- this. getid.enabled = true;
- }
- return "";
- }
Step Two: The program will get the only indication of encryption
- //Encryption
- static public string Encrypt (string plaintext)
- {
- string key_64 = "dafei250";
- string iv_64 = "DAFEI500";
- byte [] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
- byte [] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (iv_64);
- DESCryptoServiceProvider CryptoProvider = new descryptoserviceprovider ();
- int i = cryptoprovider.keysize;
- MemoryStream ms = new MemoryStream ();
- CryptoStream CST = new CryptoStream (MS, Cryptoprovider.createencryptor (Bykey, Byiv), CryptoStreamMode.Write) ;
- StreamWriter sw = new StreamWriter (CST);
- Sw. Write (plaintext);
- Sw. Flush ();
- Cst. FlushFinalBlock ();
- Sw. Flush ();
- return Convert.tobase64string (Ms. GetBuffer (), 0, (int) Ms. Length);
- }
Step three: You will decrypt the encrypted logo (when you sign up)
- //Decryption
- Public static String Decrypt (String cyphertext)
- {
- string key_64 = "haeren55"; //Must be 8 characters (64Bit)
- string iv_64 = "HAEREN55"; //Must be 8 characters (64Bit)
- Try
- {
- byte [] Bykey = System.Text.ASCIIEncoding.ASCII.GetBytes (key_64);
- byte [] Byiv = System.Text.ASCIIEncoding.ASCII.GetBytes (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, Cryptoprovider.createdecryptor (Bykey, Byiv), cryptostreammode.read);
- StreamReader sr = New StreamReader (CST);
- return Sr. ReadToEnd ();
- }
- Catch { return " cannot decrypt !";}
- }
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.