c#大量函數(shù)費(fèi)下載_第1頁
c#大量函數(shù)費(fèi)下載_第2頁
c#大量函數(shù)費(fèi)下載_第3頁
c#大量函數(shù)費(fèi)下載_第4頁
免費(fèi)預(yù)覽已結(jié)束,剩余82頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingMicrosoft.Win32;〃對(duì)注冊(cè)表操作usingSystem.Collections;〃使用ArraylistusingSystem.Security.Cryptography;〃加密解密usingSystem.10;〃文件操作usingSystem.Runtime.InteropServices;〃調(diào)用DLLDllImportusingSystem.Management;〃獲取硬件信息usingSystem.Net; 〃獲取IP地址是用到usingSystem.Drawing; //imageusingSystem.Net.Networkinformation;//ping用至リusingSystem.Text.RegularExpressions; 〃正貝リusingSystem.Data;usingSystem.Data.SqlClient;usingMicrosoft.VisualBasic; 〃簡(jiǎn)體轉(zhuǎn)繁體時(shí)用到usingSystem.Web;//htmlUrlEncodeusingSystem.Net.Sockets;usingSystem.Drawing.Drawing2D;〃圖像操作usingSystem.Drawing.Imaging;〃圖像操作namespace函數(shù)庫〃注冊(cè)表操作publicclassGFRegReadWrite(III<summary>//Z讀取路徑為keypath,鍵名為keyname的注冊(cè)表鍵值,缺省返回defIII</summary>III<paramname二〃rootkey"X/param>///<paramname="keypath〃>路徑く/param〉III<paramname二〃keyname”〉鍵名く/param>III<paramname二"rtn”〉默認(rèn)為nullく/param>III<returns></returns>staticpublicboolGetRegVal(RegistryKeyrootkey,stringkeypath,stringkeyname,outstringrtn)(rtn二;try{'RegistryKeykey二rootkey.OpenSubKey(keypath);rtn=key.GetValue(keyname).ToString();key.Close();returntrue;catch{returnfalse;///<summary>III設(shè)置路徑為keypath,鍵名為keyname的注冊(cè)表鍵值為keyvalIII</summary>III<paramname=rootkeyz,X/param>III<paramname二〃keypath"X/param>III<paramname二keyname〃X/param>III<paramname二〃keyval〃>く/param>III<returns></returns>staticpublicboolSetRegVal(RegistryKeyrootkey,stringkeypath,stringkeyname,stringkeyval)(try(RegistryKeykey=rootkey.OpenSubKey(keypath,true);if(keyニニnull)key=rootkey.CreateSubKey(keypath);key.SetValue(keyname,(object)keyval);key.Close();returntrue;)catch{returnfalse;III創(chuàng)建路徑為keypath的鍵privateRegistryKeyCreateRegKey(RegistryKeyrootkey,stringkeypath)tryreturnrootkey.CreateSubKey(keypath);catchreturnnull;))III刪除路徑為keypath的子項(xiàng)privateboolDelRegSubKey(RegistryKeyrootkey,stringkeypath){try(rootkey.DeleteSubKey(keypath);returntrue;)catch(returnfalse;))III刪除路徑為keypath的子項(xiàng)及其附屬子項(xiàng)privateboolDelRegSubKeyTree(RegistryKeyrootkey,stringkeypath)|try(rootkey.DeleteSubKeyTree(keypath);returntrue;)catch(returnfalse;))III刪除路徑為keypath下鍵名為keyname的鍵值privateboolDelRegKeyVal(RegistryKeyrootkey,stringkeypath,stringkeyname)(try{RegistryKeykey=rootkey.OpenSubKey(keypath,true);key.DeleteValue(keyname);returntrue;)catchreturnfalse;〃類型轉(zhuǎn)換publicclassGFConvert(///<summary>//Z字符串轉(zhuǎn)換char數(shù)組///</summary>///<paramname二in_strz,X/param>III<paramname二in_len〃〉く/param>III<returns></returns>publicstaticchart]string2chararray(stringin_str,intin_len)|chart]ch=newchartin_len];in_str.ToCharArray().CopyTo(ch,0);returnch;)III<summary>IIIchar數(shù)組轉(zhuǎn)換字符串///</summary>III<paramname=in_str〃>く/param>III<returns></returns>publicstaticstringchararray2string(chart]in_str){stringout_str;out_str=newstring(in_str);inti=out_str.IndexOf(‘、〇',0);if(i==-1)i=16;returnout_str.Substring(0,i);)III<summary>IIIbyte數(shù)組轉(zhuǎn)換字符串III</summary>///<paramname二in_str"X/param>III<returnsX/returns>publicstaticstringbytearray2string(byte[]in_str)stringout_str;out_str=System.Text.Encoding.Default.GetString(in_str);returnout_str.Substring(0,out_str.IndexOf(‘、0’,0));III<summary>III字符串轉(zhuǎn)換byte數(shù)組注意轉(zhuǎn)換出來會(huì)使原來的bytearray長度變短III</summary>III<paramname=in_strz,X/param>III<returns></returns>publicstaticbyte[]string2bytearray(stringin_str)(returnSystem.Text.Encoding.Default.GetBytes(in_str);)III<summary>//Z字符串轉(zhuǎn)換byte數(shù)組長度為傳如的長度III</summary>III<paramname=〃in_str〃>傳入字符串く/param>III<paramname二〃iLen”>目標(biāo)字節(jié)數(shù)組長度く/param>III<returns></returns>publicstaticbyte[]string2bytearray(stringin_str,intiLen)(byte[]bytes二newbyteEiLen];byte[]bsources二System.Text.Encoding.Default.GetBytes(in_str);Array.Copy(bsources,bytes,bsources.Length);returnbytes;)III<summary>II/將字符串編碼為Base64字符串III</summary>III<paramname二"str"X/param>///<returns></returns>publicstaticstringBase64Encode(stringstr){byte[]barray;barray=Encoding.Default.GetBytes(str);returnConvert.ToBase64String(barray);///<summary>III將Base64字符串解碼為普通字符串III</summary>III<paramname=/zstrz,X/param>///<returns></returns>publicstaticstringBase64Decode(stringstr){byte[]barray;try(barray=Convert.FromBase64String(str);returnEncoding.Default.GetString(barray);)catch{returnstr;III<summary>III圖片轉(zhuǎn)換byte數(shù)組III</summary>///<paramname=pic”>く/param>III<paramname二〃fmt〃X/param>///<returns></returns>publicstaticbyte[]image_Image2Byte(Imagepic,System.Drawing.Imaging.ImageFormatfmt)(MemoryStreammem=newMemoryStream();pic.Save(mem,fmt);mem.Flush();returnmem.ToArray();)III<summary>IIIbyte數(shù)組轉(zhuǎn)換圖片III</summary>III<paramname="bytes”〉く/param>III<returns></returns>publicstaticImageimage_Byte2Image(byte[]bytes)(MemoryStreammem=newMemoryStream(bytes,true);mem.Read(bytes,0,bytes.Length);mem.Flush();Imageaa=Image.FromStream(mem);returnaa;)///<summary>IIIip轉(zhuǎn)換長整形III</summary>///<paramname="strIP></param>III<returns></returns>publicstaticlongIP2Long(stringstrIP)(long[]ip=newlong[4];string[]s=strip.Split('.‘);ip[0]=long.Parse(s[Oj);ip[l]=long.Parse(s[l]);ip[2]=long.Parse(s[2]);ip[3]=long.Parse(s[3]);return(ip[〇]?24)+(ip[l]?16)+(ip[2]?8)+ip[3];)III<summary>III長整形轉(zhuǎn)換IPIII</summary>III<paramname="longIP//X/param>III<returnsX/returns>publicstaticstringLong2IP(longlonglP)Slfingl)uild(?rsb=newStiingBuildcr("");sb.Append(longlP?24);sb.Append(".");〃將高8位置0,然后右移16為sb.Append((longlP&OxOOFFFFFF)>>16);sb.Append(".");sb.Append((longlP&OxOOOOFFFF)?8);sb.Append(〃?〃);sb.Append((longlP&OxOOOOOOFF));returnsb.ToStringO;)III<summary>II!將8位日期型整型數(shù)據(jù)轉(zhuǎn)換為日期字符串?dāng)?shù)據(jù)III</summary>III<paramname二〃date”)整型日期く/param>III<paramnameエ〃chnType〃>是否以中文年月日輸出く/param>III<returns></returns>publicstaticstringFormatDate(intdate,boolchnType)|stringdateStr=date.ToStringO;if(date<=0|IdateStr.Length!=8)returndateStr;if(chnType)returndateStr.Substring(0,4)+“年"+dateStr.Substring(4,2)+〃月〃+dateStr.Substring(6)+〃日〃;returndateStr.Substring(0,4)+“ー〃+dateStr.Substring(4,2)+ +dateStr.Substring(6);III<summary>IIIstring型轉(zhuǎn)換為bool型III</summary>III<paramname二"strValue”〉要轉(zhuǎn)換的字符串く/param>III<paramname二〃defValue”〉缺省值く/param>II!くreturns)轉(zhuǎn)換后的bool類型結(jié)果く/returns〉publicstaticboolStrToBool(objectexpression,booldefValue)(if(expression!=null)returnStrToBool(expression,defValue);returndefValue;Ill<summary>///string型轉(zhuǎn)換為bool型III</summary>III<paramname二〃strValue”〉要轉(zhuǎn)換的字符串く/param>III<paramname二〃defValue”>缺省值く/param>IIIくreturns〉轉(zhuǎn)換后的bool類型結(jié)果く/returns》publicstaticboolStrToBool(stringexpression,booldefValue){if(expression!=null)(if(string.Compare(expression,〃true〃,true)==0)returntrue;elseif(string.Compare(expression,“false”,true)==0)returnfalse;)returndefValue;)III<summary>III將對(duì)象轉(zhuǎn)換為Int32類型III</summary>III<paramname二〃strValue〃〉要轉(zhuǎn)換的字符串</param>III<paramname二〃defValue”〉缺省值く/param〉//!くreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticintObjectToInt(objectexpression){returnObjectToInt(expression,0);)III<summary>//Z將對(duì)象轉(zhuǎn)換為Int32類型III</summary>III<paramname二〃strValue〃〉要轉(zhuǎn)換的字符串く/param〉III<paramname二〃defVaiue〃〉缺省值く/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果〈/returns〉publicstaticintObjectToInt(objectexpression,intdefValue)(if(expression!=null)returnStrToInt(expression.ToString(),defValue);returndefValue;///<summary>//Z將對(duì)象轉(zhuǎn)換為Int32類型,轉(zhuǎn)換失敗返回〇III</summary>III<paramname="str”〉要轉(zhuǎn)換的字符串く/param>IIIくreturns)轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticintStrToInt(stringstr)(returnStrToInt(str,0);)III<summary>〃/將對(duì)象轉(zhuǎn)換為Int32類型///</summary>III<paramname="str”〉要轉(zhuǎn)換的字符串く/param〉III<paramname="defValue”〉缺省值く/param〉//!くreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticintStrToInt(stringstr,intdefValue)(if(string.IsNullOrEmpty(str)|jstr.Trim().Length>=11II!Regex.IsMatch(str.TrimO,@"へ([-][〇ー9])[〇-9]*(\.\w*)?$〃))returndefValue;intrv;if(Int32.TryParse(str,outrv))returnrv;returnConvert.Tolnt32(StrToFloat(str,defValue));)III<summary>IIIstring型轉(zhuǎn)換為float型III</summary>III<paramname二〃strValue”〉要轉(zhuǎn)換的字符串</param>III<paramname二"defValue"〉缺省值く/param〉//1くreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticfloatStrToFloat(objectstrValue,floatdefValue){if((strValue==null))returndefValue;returnStrToFloat(strValue.ToString(),defValue);)III<summary>IIIstring型轉(zhuǎn)換為float型Ill</summary>III<paramname二〃strValue〃>要轉(zhuǎn)換的字符串</param>III<paramname二〃defValue”〉缺省值く/param>IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果〈/returns〉publicstaticfloatObjectToFloat(objectstrValue,floatdefValue){if((strValue==null))returndefValue;returnStrToFloat(strValue.ToString(),defValue);)III<summary>///string型轉(zhuǎn)換為float型III</summary>III<paramname="strValue"〉要轉(zhuǎn)換的字符串く/param〉III<paramname二〃defValue〃〉缺省值く/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果〈/returns〉publicstaticfloatObjectToFloat(objectstrValue)(returnObjectToFloat(strValue.ToString(),0);)III<summary>IIIstring型轉(zhuǎn)換為float型III</summary>III<paramname二〃strValue")要轉(zhuǎn)換的字符串く/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果〈/returns〉publicstaticfloatStrToFloat(stringstrValue)(if((strValue==null))return0;returnStrToFloat(strValue.ToString(),0);)III<summary>IIIstring型轉(zhuǎn)換為float型///</summary>III<paramname二〃strValue"〉要轉(zhuǎn)換的字符串〈/param〉III<paramname二"defVaiue"〉缺省值〈/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果〈/returns〉publicstaticfloatStrToFloat(stringstrValue,floatdefValue)if((strValue==null)||(strValue.Length>10))returndefValue;floatintValue=defValue;if(strValue!=null)(boolIsFloat=Regex.IsMatch(strValue,@”([-]|[0-9])[0-9]*(\.、w*)?$〃);if(IsFloat)float.TryParse(strValue,outintValue);)returnintValue;)III<summary>//Z將對(duì)象轉(zhuǎn)換為日期時(shí)間類型//Zく/summary〉III<paramname="str”>要轉(zhuǎn)換的字符串く/param>III<paramname="defValue"〉缺省值く/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticDateTimeStrToDateTime(stringstr,DateTimedefValue)if(Istring.IsNullOrEmpty(str))(DateTimedateTime;if(DateTime.TryParse(str,outdateTime))returndateTime;returndefValue;III<summary>III將對(duì)象轉(zhuǎn)換為日期時(shí)間類型III</summary>III<paramname二"str"〉要轉(zhuǎn)換的字符串く/param〉IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticDateTimeStrToDateTime(stringstr){returnStrToDateTime(str,DateTime.Now);///<summary>Ill將對(duì)象轉(zhuǎn)換為日期時(shí)間類型IIIく/summary)III<paramname二〃obj”〉要轉(zhuǎn)換的對(duì)象く/param>IIIくreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉publicstaticDateTimeObjectToDateTime(objectobj)(returnStrToDateTime(obj.ToStringO);)III<summary>〃/將對(duì)象轉(zhuǎn)換為日期時(shí)間類型III</summary>III<paramname二〃obj”〉要轉(zhuǎn)換的對(duì)象く/param〉III<paramname二〃defVaiue〃〉缺省值く/param〉//!くreturns〉轉(zhuǎn)換后的int類型結(jié)果く/returns〉DateTimepublicstaticDateTimeObjectToDateTime(objectobj,defValue)DateTime(returnStrToDateTime(obj.ToStringO,defValue);)III<summary>III替換回車換行符為html換行符///</summary>publicstaticstringStrFormat(stringstr){stringstr2;if(strニニnull){str2二;)else{str=str.Replace(〃、r\n,“くbr/〉);str=str.Replace(z/\n,z,〃くbr/〉〃);str2二str;)returnstr2;)III<summary>//Z轉(zhuǎn)換為簡(jiǎn)體中文III</summary>publicstaticstringToSChinese(stringstr){returnStrings.StrConv(str,VbStrConv.SimplifiedChinese,0);///<summary>//Z轉(zhuǎn)換為繁體中文III</summary>publicstaticstringToTChinese(stringstr){returnStrings.StrConv(str,VbStrConv.TraditionalChinese,0);III<summary>III清除字符串?dāng)?shù)組中的重復(fù)項(xiàng)III</summary>III<paramname二〃strArray〃>字符串?dāng)?shù)組〈/param>III<paramname二〃maxElementLength〃>字符串?dāng)?shù)組中單個(gè)元素的最大長度く/param>III<returns></returns>publicstaticstring[]DistinctStringArray(string[]strArray,intmaxElementLength){Hashtableh二newHashtable();foreach(stringsinstrArray){stringk=s;if(maxElementLength>0&&k.Length>maxElementLength)(k=k.Substring(0,maxElementLength);)h[k.Trim()]=s;)string[]result=newstring[h.Count];h.Keys.CopyTo(result,0);returnresult;III<summary>III清除字符串?dāng)?shù)組中的重復(fù)項(xiàng)III</summary>III<paramname二〃strArray”>字符串?dāng)?shù)組く/param>///<returns></returns>publicstaticstring[]DistinctStringArray(string[]strArray){returnDistinctStringArray(strArray,0);〃加密解密publicclassGFEncrypt{III<summary>IIIDES加密III</summary>///<paramname=〃pToEncrypt”>加密字符串</param>III<paramname二〃sKey”>密鑰く/param>III<returns></returns>publicstaticstringstring_Encrypt(stringpToEncrypt,stringsKey)(if(pToEncrypt== )return;if(sKey.Length<8)sKey=sKey+"xuE29xWp〃;if(sKey.Length>8)sKey=sKey.Substring(0,8);DESCryptoServiceProviderdes=newDESCryptoServiceProvider();〃把字符串放到byte數(shù)組中〃原來使用的UTF8編碼,我改成Unicode編碼了,不行byte[]inputByteArray=Encoding.Default.GetBytes(pToEncrypt);〃建立加密對(duì)象的密鑰和偏移量〃原文使用ASCI【Encoding.ASCII方法的GetBytes方法〃使得輸入密碼必須輸入英文文本des.Key=ASCIIEncoding.Default.GetBytes(sKey);des.IV=ASCIIEncoding.Default.GetBytes(sKey);MemoryStreamms=newMemoryStream();CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);//Writethebytearrayintothecryptostream//(Itwillendupinthememorystream)cs.Write(inputByteArray,0,inputByteArray.Length);cs.FlushFinalBlock();//Getthedatabackfromthememorystream,andintoastringStringBuilderret=newStringBuilder();foreach(bytebinms.ToArray())(//Formatashexret.AppendFormat("{O:X2}",b);)ret.ToStringO;returnret.ToStringO;III<summary>IIIDES解密III</summary>III<paramname二〃pToDecryp1:“>解密字符串く/param>III<paramname="sKey"〉解密密鑰く/param>///<paramname="outstr,/>i^[Bl{S</param>III<returns></returns>publicstaticboolstring_Decrypt(stringpToDecrypt,stringsKey,outstringoutstr){if(pToDecryptニニ”"ヽ{outstr= ;returntrue;);if(sKey.Length<8)sKey二sKey+〃xuE29xWp〃;if(sKey.Length>8)sKey二sKey.Substring(0,8);try{,DESCryptoServiceProviderdes=newDESCryptoServiceProvider();//Puttheinputstringintothebytearraybyte[]inputByteArray=newbyte[pToDecrypt.Length/2];for(intx=0;x<pToDecrypt.Length/2;x++)inti二(Convert.Tolnt32(pToDecrypt.Substring(x*2,2),16));inputByteArray[x]=(byte)i;)〃建立加密對(duì)象的密鑰和偏移量,此值重要,不能修改des.Key=ASCIIEncoding.Default.GetBytes(sKey);des.IV=ASCIIEncoding.Default.GetBytes(sKey);MemoryStreamms=newMemoryStream();CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);//Flushthedatathroughthecryptostreamintothememorystreamcs.Write(inputByteArray,0,inputByteArray.Length);cs.FlushFinalBlockO;//Getthedecrypteddatabackfromthememorystream〃建立StringBuild對(duì)象,CreateDecrypt使用的是流對(duì)象,必須把解密后的文本變成流對(duì)象StringlkiiIderret=newStringBuilckir();outstr=System.Text.Encoding.Default.GetString(ms.ToArray());returntrue;)catch{outstr= ;returnfalse;III<summary>III加密III</summary>publicclassAES(〃默認(rèn)密鑰向量privatestaticbyte口Keys={0x41,0x72,0x65,0x79,0x6F,0x75,0x6D,0x79,0x53,0x6E,0x6F,0x77,0x6D,0x61,0x6E,0x3F};publicstaticstringEncode(stringencryptString,stringencryptKey)encryptKey=GF_GET.GetSubString(encryptKey,32, );encryptKey=encryptKey.PadRight(32,'');RiJndaelManagedrijndaelProvider=newRijndae1Managed();rijndaelProvider.Key=Encoding.UTF8.GetBytes(encryptKey.Substring(0,32));rijndaelProvider.IV=Keys;ICryptoTransformrijndae1Encrypt=rijndaelProvider.CreateEncryptor();byte[]inputData=Encoding.UTF8.GetBytes(encryptString);byte[]encryptedData=rijndaelEncrypt.TransformFinalBlock(inputData,0,inputData.Length);returnConvert.ToBase64String(encryptedData);)publicstaticstringDecode(stringdecryptString,stringdecryptKey)(try(decryptKey=GF_GET.GetSubString(decryptKey,32,つ;decryptKey=decryptKey.PadRight(32,'');RiJndaelManagedrijndae1Provider=newRijndaeIManaged();rijndaelProvider.Key=Encoding.UTF8.GetBytes(decryptKey);rijndaelProvider.IV=Keys;ICryptoTransformrijndaelDecrypt=rijndaelProvider.CreateDecryptor();byte[]inputData=Convert.FromBase64String(decryptString);byte[]decryptedData=rijndaelDecrypt.TransformFinalBlock(inputData,0,inputData.Length);returnEncoding.UTF8.GetString(decryptedData);)catchreturn

III<summary>//Z加密///</summary>publicclassDES〃默認(rèn)密鑰向量privatestaticbyte[]Keys={0x12,0x34,0x56,0x78,0x90,OxAB,OxCD,OxEFOxAB,OxCD,OxEF};III<summary>///DES加密字符串III</summary>III<paramname二〃encryptString〃>待加密的字符串</param>III<paramname="encryplKey”〉加密密鑰,要求為8位く/param>IIIくreturns》加密成功返冋加密后的字符串,失敗返回源串</returns>publicstaticstringEncode(stringencryptString,stringencryptKey)encryptKey=GF_GET.GetSubString(encryptKey,8,"");encryptKey=encryptKey.PadRight(8,'');byte[]rgbKey=Encoding.UTF8.GetBytes(encryptKey.Substring(0,8));byte[]rgblV=Keys;byte[]inputByteArray=Encoding.UTF8.GetBytes(encryptString);DESCryptoServiceProviderdCSP=newDb'SCryptoServicel^rovider();MemoryStreninmStream二newMenioryStreamO;Crypt<)StreumcStream=newCrypt()Str(?;nn(mStream,dCSP.CreateEncryptor(rgbKey,rgblV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlockO;returnConvert.ToBase64String(mStream.ToArray());III<summary>IllDES解密字符串III</summary>III<paramnameエ〃decryptString”>待解密的字符串く/param>III<paramname="decryptKey〃>解密密鑰,要求為8位,和加密密鑰相同く/param>IIIくreturns〉解密成功返回解密后的字符串,失敗返源串</returns>publicstaticstringDecode(stringdecryptString,stringdecryptKey)(try{decryptKey=GF_GET.GetSubString(decryptKey,8,);decryptKey=decryptKey.PadRight(8,'');byte[]rgbKey=Encoding.UTF8.GetBytes(decryptKey);byte[]rgblV=Keys;byte[]inputByteArray=Convert.FromBase64String(decryptString);DESCryptoServiceProviderDCSP=newDESCryptoServiceProvider();MemoryStreammStream=newMemoryStream();CryptoStreamcStream=newCryptoStream(mStream,DCSP.CreateDecryptor(rgbKey,rgblV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlockO;returnEncoding.UTF8.GetString(mStream.ToArray());)catch{return;///<summary>IIIMD5函數(shù)III</summary>III<paramname二〃str〃〉原始字符串</param>//!くreturns〉MD5結(jié)果く/returns〉publicstaticstringMD5(stringstr)(byte[]b=Encoding.UTF8.GetBytes(str);b=newMD5CryptoServiceProvider().ComputeHash(b);stringret二;for(inti=0;i<b.Length;i++)ret+=b[i].ToString("x").PadLeft(2,‘〇');returnret;)III<summary>IIISHA256函數(shù)III</summary>///III<paramname="str"〉原始字符串く/param>IIIくreturns>SHA256結(jié)果く/returns)publicstaticstringSHA256(stringstr){byte[]SHA256Data=Encoding.UTF8.GetBytes(str);SHA256ManagedSha256=newSHA256Managed();byte[]Result=Sha256.ComputeHash(SHA256Data);returnConvert.ToBase64String(Result);〃返冋長度為44字節(jié)的字符串)III<summary>///返回HTML字符串的編碼結(jié)果III</summary>III<paramname="str"〉字符串く/param〉IIIくreturns〉編碼結(jié)果く/returns〉publicstaticstringHtmlEncode(stringstr){returnHttpUtility.HtmlEncode(str);)III<summary>II/返回HTML字符串的解碼結(jié)果III</summary>III<paramname二"str"〉字符串く/param〉//Zくreturns〉解碼結(jié)果く/returns〉publicstaticstringHtmlDecode(stringstr)returnHttpUtility.HtmlDecode(str);Ill<summary>III返冋URL字符串的編碼結(jié)果III</summary>III<paramname=str>字符串く/param>IIIくreturns》編碼結(jié)果く/returns)publicstaticstringUrlEncode(stringstr)(returnHttpUtility.UrlEncode(str);)III<summary>II/返回URL字符串的編碼結(jié)果III</summary>III<paramname二〃str〃>字符串く/param>IIIくreturns》解碼結(jié)果く/returns》publicstaticstringUrlDecode(stringstr)(returnHttpUtility.UrlDecode(str);〃讀寫INIpublicclassGFINI([DI1ImportC,kernel32,z)]privatestaticexternlongWritePrivateProfileString(stringsection,stringkey,stringval,stringfilePath);[DllImport("kerneI32")]privatestaticexternintGetPrivateProfi1eString(stringsection,stringkey,stringdef,StringBuilderretVal,intsize,stringfilePath);[DllImport("kernel32.dll")]publicstaticexternintBeep(intdwFreq,intdwDuration);//讀inipublicstaticvoidiniFile_SetVal(stringin_filename,stringSection,stringKey,stringValue)(WritePrivateProfi1eString(Section,Key,Value,in_filename);〃寫INIpublicstaticstringiniFile_GetVal(stringin_filename,stringSection,stringKey)StringBuiIdertemp=newStringBui1dor(255);inti=GetPrivateProfileString(Section,Key,,temp,255,in_filename);if(i==0)returnelsereturntemp.ToStringO;〃硬件信息publicclassGFHardware(III<summary>IIIcpu序列號(hào)III</summary>III<returns></returns>publicstaticstringgetID_CpuId()stringcpulnfo=""ノ/cpu序列號(hào)ManagementClasscimobject=newManagementclass(z,Win32Processor"");ManagementObjectCollectionmoc=cimobject.Getlnstances();foreach(Managementobjectmoinmoc)cpulnfo=mo.Properties[,zProcessorIdz,].Value.ToStringO;returncpulnfo;)III<summary>III硬盤ID號(hào)III</summary>///<returns></returns>publicstaticstringgetlDHardDiskldO{stringHDid二;Managementclasscimobject=newManagementclass(zzWin32DiskDrive");ManagementObjectCo11ectionmoc=cimobject.Getlnstances();foreach(Managementobjectmoinmoc){HDid=(string)mo.Properties[^ModeT7].Value;)returnHDid;)III<summary>//Z獲取網(wǎng)卡MacAddressIII</summary>III<returns></returns>publicstaticstringget!D_NetCard!d()(stringNCid二;Managementclassme=newManagementclass(,,Win32_NetworkAdapterConfigurationz);ManagementObjectCo11ectionmoc=me.Getlnstances();foreach(Managementobjectmoinmoc)(if((bool)mo[〃IPEnabled〃]==true)NCid=mo["MacAddress"].ToStringO;mo.Dispose();}returnNCid;〃網(wǎng)絡(luò)部分publicclassGF_Network(/**C#完整的通信代碼(點(diǎn)對(duì)點(diǎn),點(diǎn)對(duì)多,同步,異步,UDP,TCP)*/u/20080619/08/dcef3fe2-f95b-4918-8edb-36d48a3do528_2.html*Ill<summary>III獲取IP地址返回第一個(gè)III</summary>III<returns></returns>publicstaticstringgetIP_This()(IPHostEntryhostinfo=Dns.GetHostEntry(Dns.GetHostName());IPAddress[]address=hostInfo.AddressList;if(address.Length==0)return;elsereturnaddress[0].ToStringO;)III<summary>IIIpingIP地址timeout局域網(wǎng)用200,廣域網(wǎng)用2000III</summary>III<paramname=〃ip”>IP地址く/param>III<paramname二〃timeout”〉超時(shí)毫秒く/param>III<returns></returns>publicstaticboolping(stringip,inttimeout)(IPAddressipadd;if(!IPAddress.TryParse(ip,outipadd))(returnfalse;)PingpingSender二newPingO;PingReplyreply=pingSender.Send(ip,timeout,newByteロ{Convert.ToByte(l)});if(reply.Status==IPStatus.Success)returntrue;elsereturnfalse;}III<summary>III判讀是否是IP地址III</summary>///<paramname二in_str></param>III<returnsX/returns>publicstaticboolIsIPStr(stringin_str)if(in_str.ReplaceC"., ).Length!二in_str.Length-3)returnfalse;try{'IPAddressip=IPAddress.Parse(in_str);returntrue;)catch(returnfalse;)}///<summary>IIIFTP類III</summary>publicclassFTP|ttregion變量聲明III<summary>III服務(wù)器連接地址III</summary>publicstringserver;III<summary>//Z登陸帳號(hào)III</summary>publicstringuser;///<summary>//Z登陸口令I(lǐng)II</summary>publicstringpass;III<summary>II!端口號(hào)III</summary>publicintport;III<summary>III無響應(yīng)時(shí)間(FTP在指定時(shí)間內(nèi)無響應(yīng))III</summary>publicinttimeout;III<summary>〃/服務(wù)器錯(cuò)誤狀態(tài)信息III</summary>publicstringerrormessage;///<summary>///服務(wù)器狀態(tài)返回信息III</summary>privatestringmessages;III<summary>///服務(wù)器的響應(yīng)信息III</summary>privatestringresponseStr;III<summary>II!鏈接模式(主動(dòng)或被動(dòng),默認(rèn)為被動(dòng))III</summary>privateboolpassive_mode;///<summary>//Z上傳或下載信息字節(jié)數(shù)III</summary>privatelongbytes_total;III<summary>//Z上傳或下載的文件大小///</summary>privatelongfile_size;III<summary>III主套接字III</summary>privateSocketmain_sock;III<summary>//Z要鏈接的網(wǎng)絡(luò)地址終結(jié)點(diǎn)III</summary>privateIPEndPointmain_ipEndPoint;///<summary>//Z偵聽套接字III</summary>privateSocketlistening_sock;III<summary>III數(shù)據(jù)套接字///</summary>privateSocketdata_sock;III<summary>III要鏈接的網(wǎng)絡(luò)數(shù)據(jù)地址終結(jié)點(diǎn)III</summary>privateIPEndPointdata_ipEndPoint;III<summary>//Z用于上傳或下載的文件流對(duì)象III</summary>privateFileStreamfile;///<summary>///與FTP服務(wù)器交互的狀態(tài)值III</summary>privateintresponse;III<summary>//Z讀取并保存當(dāng)前命令執(zhí)行后從FTP服務(wù)器端返回的數(shù)據(jù)信息II!く/summary〉privatestringbucket;III<summary>//Z默認(rèn)byte數(shù)組長度III</summary>privateintbyteLength=512;ttendregionttregion構(gòu)造函數(shù)III<summary>//Z構(gòu)造函數(shù)///</summary>publicFTP(){server=null;user=null;pass=null;port=21;passive_mode=true;main_sock=null;main_ipEndPoint=null;listening_sock=null;data_sock=null;data_ipEndPoint=null;file=null;bucket=bytes_total=0;timeout=10000; 〃無響應(yīng)時(shí)間為10秒messages二;errormessage= ;)III<summary>III構(gòu)造函數(shù)III</summary>III<paramname二〃server"〉服務(wù)器IP或名稱く/param>III<paramname二〃user”〉登陸帳號(hào)く/param〉///<paramname二〃pass”〉登陸口令く/param〉publicFTP(stringserver,stringuser,stringpass)this.server=server;this.user=user;this,pass=pass;port=21;passive_mode=true;main_sock=null;main_ipEndPoint=null;listening_sock=null;data_sock=null;data_ipEndPoint=null;file=null;bucket=bytes_total=0;timeout=10000; 〃無響應(yīng)時(shí)間為10秒messages=";errormessage二;)III<summary>III構(gòu)造函數(shù)III</summary>III<paramname="server"〉服務(wù)器IP或名稱く/param>III<paramname="porl”>端口號(hào)く/param>III<paramname二〃user”)登陸帳號(hào)く/param>III<paramname二〃pass")登陸口令く/param>publicFTP(stringserver,intport,stringuser,stringpass)(this.server=server;this.user=user;this,pass=pass;this,port=port;passive_mode=true;main_sock=null;main_ipEndPoint=null;listening_sock=null;data_sock=null;data_ipEndPoint=null;file=null;bucket=bytestotal=0;timeout=10000; 〃無響應(yīng)時(shí)間為10秒messages=errormessageIll<summary>III構(gòu)造函數(shù)III</summary>III<paramname二〃server"〉服務(wù)器IP或名稱く/param>III<paramname二〃porJ>端口號(hào)く/param>III<paramname二〃user〃>登陸帳號(hào)く/param>III<paramname二〃pass”》登陸口令く/param>///<paramname二〃mode"〉璉接方式く/param>publicFTP(stringserver,intport,stringuser,stringpass,intmode)(this.server=server;this,user二user;this.pass二pass;this.port二port;passive_mode=mode<=1?true:false;main_sock二null;main_ipEndPoint=null;listening_sock二null;data_sock二null;data_ipEndPoint二null;file=null;bucket二;bytes_total=0;this,timeout二!0000;〃無響應(yīng)時(shí)間為10秒messages二;errormessage二;)III<summary>III構(gòu)造函數(shù)III</summary>III<paramname二"server"〉服務(wù)器IP或名稱く/param〉III<paramname二port"‘端口號(hào)く/param〉III<paramname="user"〉登陸帳號(hào)く/param〉III<paramname二pass"〉登陸口令く/param〉III<paramname二mode"〉鏈接方式く/param〉III<paramname="timeout”〉無響應(yīng)時(shí)間(限時(shí)),單位:秒(小于或等于〇為不受時(shí)間限制)</param>publicFTP(stringserver,intport,stringuser,stringpass,intmode,inttimeout_sec)this.server=server;this.user=user;this,pass=pass;this,port=port;passive_mode=mode<=1?true:false;main_sock=null;main_ipEndPoint=null;listening_sock=null;data_sock=null;data_ipEndPoint=null;file=null;bucket=bytes_total=0;this,timeout=(timeout_sec<=0)?int.MaxValue:(timeout_sec*1000);〃無響應(yīng)時(shí)間messages=errormessage二;)#endregionttregion屬性III<summary>//Z當(dāng)前是否已連接III</summary>publicboolIsConnected(get(if(main_sock!=null)returnmain_sock.Connected;returnfalse;III<summary>//Z當(dāng)message緩沖區(qū)有數(shù)據(jù)則返回III</summary>publicboolMessagesAvailable(getif(messages.Length>0)returntrue;returnfalse;III<summary>II!獲取服務(wù)器狀態(tài)返冋信息,并清空messages變量III</summary>publicstringMessages(get(stringtmp=messages;messages二;returntmp;))III<summary>//Z最新指令發(fā)出后服務(wù)器的響應(yīng)III</summary>publicstringResponseString(get(returnresponseStr;II

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論