. NET Common skills _ software registration code

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Management;usingUtility;usingExdatacontrol;usingSystem.Collections;usingMicrosoft.Win32;namespacemytool{ Public classSoftreg {/// <summary>        ///get the Hard disk volume label/// </summary>        /// <returns></returns>         Public Static stringGetdiskvolumeserialnumber () {ManagementClass mc=NewManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObject Disk=NewManagementObject ("win32_logicaldisk.deviceid=\ "c \""); Disk.            Get (); returnDisk. GetPropertyValue ("VolumeSerialNumber").        ToString (); }        /// <summary>        ///Get CPU Serial number/// </summary>        /// <returns></returns>         Public Static stringgetcpu () {stringSTRCPU =NULL; ManagementClass mycpu=NewManagementClass ("Win32_Processor"); Managementobjectcollection mycpucollection=mycpu.getinstances (); foreach(ManagementObject MyObjectinchmycpucollection) {STRCPU= myobject.properties["Processorid"].            Value.tostring (); }            returnstrcpu; }        /// <summary>        ///Generate machine code/// </summary>        /// <returns></returns>         Public Static stringGetmnum () {stringStrnum = GETCPU () +Getdiskvolumeserialnumber (); stringStrmnum = strnum.substring (0, -);//intercept the first 24 bits as machine code            returnStrmnum; }         Public Static int[] Intcode =New int[127];//Store Key         Public Static Char[] CharCode =New Char[ -];//storing ASCII code         Public Static int[] intnumber =New int[ -];//storing ASCII code values//initializing the key         Public Static voidSetintcode () { for(inti =1; i < intcode.length; i++) {Intcode[i]= i%9; }        }        /// <summary>        ///Generate registration Code/// </summary>        /// <returns></returns>         Public Static stringGetrnum () {setintcode (); stringStrmnum =Getmnum ();  for(inti =1; i < charcode.length; i++)//Storage Machine Code{Charcode[i]= Convert.tochar (strmnum.substring (i-1,1)); }             for(intj =1; J < Intnumber.length; J + +)//Changing the ASCII code value{Intnumber[j]= Convert.ToInt32 (Charcode[j]) +Intcode[convert.toint32 (Charcode[j]); }            stringStrasciiname ="";//Registration Code             for(intK =1; K < Intnumber.length; k++)//Generate registration Code            {                if((Intnumber[k] >= -&& Intnumber[k] <= $) || (Intnumber[k] >= $&&Intnumber[k]<= -) || (Intnumber[k] >= the&& Intnumber[k] <=122))//Judging if between 0-9, A-Z, a-Z{strasciiname+=Convert.tochar (Intnumber[k]).                ToString (); }                Else if(Intnumber[k] >122)//Judging if greater than Z{strasciiname+ = Convert.tochar (Intnumber[k]-Ten).                ToString (); }                Else{strasciiname+ = Convert.tochar (Intnumber[k]-9).                ToString (); }            }            stringStrencrypt = Utility.DESEncrypt.Encrypt (strasciiname);//Encrypt            returnStrencrypt; }        /// <summary>        ///Generate trial Registration code (take the registration code, the first n bits are changed to the current date)/// </summary>        /// <returns></returns>         Public Static stringGetbnum (exdatacontrol.exdatacenter DC) {stringStrdecrypt = Utility.DESEncrypt.Decrypt (Getrnum ());//first decrypt the registration code            stringCurrentdatetime = Dc.getserverdatetime (). Substring (0,Ten); Strdecrypt= Strdecrypt.substring (Ten, Strdecrypt.length-Ten); stringstrkey = Currentdatetime + strdecrypt;//10-bit date + 14 digits after registration code            stringStrencrypt = Utility.DESEncrypt.Encrypt (strkey);//Encrypt            returnStrencrypt; }    }}

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.