亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? shareclass.cs

?? VC++實現的加密解密類
?? CS
字號:
using System;
using System.IO ;
using System.Data ;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace Encryption_Demo
{
	/// <summary>
	/// 目的在工程中直接引用
	/// </summary>
	public class ShareClass
	{
		public ShareClass()
		{
		}
		//選擇HASH方式
		private static string [] hashs  = new string[5]{"MD5","SHA256","SHA384","SHA512","SHA1"};
		//散列文件函數,得到文件摘要
		public static byte [] HashFile(int choice,string filepath )//返回散列后的結果
		{
			FileStream fs = new FileStream(filepath ,FileMode.Open,FileAccess.Read );
			HashAlgorithm shas = HashAlgorithm.Create( hashs [choice]); 
			byte [] TheHashResult = shas.ComputeHash( fs );
			fs.Close();
			shas.Clear();
			return TheHashResult ;//Convert.ToBase64String( TheHashResult ,0 ,TheHashResult.Length );
		}
		//散列數據啦
		public static byte[] HashData(int choice,byte []hashdata)
		{			
			HashAlgorithm shas = HashAlgorithm.Create( hashs [choice]); 
			byte [] hashed = shas.ComputeHash(hashdata,0,hashdata.Length);
			return hashed ;
		}
		//比較兩個散列是否相等
		public static bool CompareHash( byte[]hashA,byte[]hashB )
		{
			if(hashA.Length != hashB.Length )		
				throw new ArgumentException(" The Hashes must be same length ! ");
			bool match = true  ;
			for( int i=0;i<hashA.Length;i++ )
			{
				if( hashA[i] != hashB[i])
					match = false ;
			}
			return match; 
		}
		//得到收到文件的時間,轉化為數組形式
		public static byte [] GetTimeNow()
		{
			//這樣轉化成的格式為:2004-11-09 13:04:28-108 23個字節
			DateTime now = DateTime.Now;
			System.Text.UTF8Encoding utf = new System.Text.UTF8Encoding();

			string month = null ;
			if(now.Month<10)
				month = "0"+now.Month.ToString();
			else
				month = now.Month.ToString();

			string day = null;
			if(now.Day<10)
				day = "0" + now.Day.ToString();
			else
				day = now.Day.ToString();

			string millisecond = null;
			if(now.Millisecond<10)
				millisecond = "00"+now.Millisecond.ToString();
			if(now.Millisecond>=10&&now.Millisecond<=99)
				millisecond = "0" + now.Millisecond.ToString();
			if(now.Millisecond>=100)
				millisecond = now.Millisecond.ToString();

			string FullFormatTime = now.Year.ToString() + "-" + month + "-" + day + " " + now.ToLongTimeString() + "-" + millisecond ;//比如:2004-11-09 13:04:28-108
			return utf.GetBytes( FullFormatTime );//now.ToString() + "-"+now.Millisecond);//now.Millisecond 表示當前日期的毫秒部分			
		}
		/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	    //對稱加密與解密函數
	    private static SymmetricAlgorithm crypt; //全局必須是靜態
		private static 	string [] sma = new string[4]{"DES","TripleDES","RC2","Rijndael"};
		//隨機產生對稱加密的鑰匙KEY和向量IV
		public static byte [] RandomKey(int choice)
		{
				SymmetricAlgorithm crypt = SymmetricAlgorithm.Create(sma[choice]);
				crypt.GenerateKey();
				return crypt.Key ;
		}
		public static byte [] RandomIV(int choice)
		{
		 	SymmetricAlgorithm crypt = SymmetricAlgorithm.Create(sma[choice]);
			crypt.GenerateIV();
			return crypt.IV ;
		}
		//對稱加密數據函數
		public static byte [] EncryptData( int choice,byte[]Key,byte[]IV,byte[]toEncryptData )
		{
			try
			{
				SymmetricAlgorithm crypt = SymmetricAlgorithm.Create(sma[choice]);
				ICryptoTransform transform = crypt.CreateEncryptor( Key,IV);	
				//Encrypt the data.
				MemoryStream ms = new MemoryStream();
				CryptoStream cs = new CryptoStream(ms ,transform, CryptoStreamMode.Write);
				//Convert the data to a byte array.
				//Write all data to the crypto stream and flush it.
				cs.Write(toEncryptData, 0, toEncryptData.Length);
				cs.FlushFinalBlock();
				//Get encrypted array of bytes.
				return ms.ToArray();
			}
			catch
			{
				throw new CryptographicException("加密出現失誤,請重新檢查輸入!");
			}
		}
		//解密數據,根據思路,此時byte[]Key,byte[]IV這些參數不再是隨機的數據而是固定的數據啦。
		public static byte[] DecryptData( int choice ,byte[]Key,byte[]IV ,byte[]toDecryptedData )
		{	
			try
			{
				SymmetricAlgorithm crypt = SymmetricAlgorithm.Create(sma[choice]);
				ICryptoTransform transform = crypt.CreateDecryptor( Key,IV );	
				MemoryStream ms = new MemoryStream( );
				//重寫這部分
				CryptoStream cs = new CryptoStream(ms, transform, CryptoStreamMode.Write);
				//Read the data out of the crypto stream.
				cs.Write( toDecryptedData , 0, toDecryptedData.Length);
				cs.FlushFinalBlock();
				return ms.ToArray() ;
			}
			catch
			{
				throw new CryptographicException("解密數據流時,出現錯誤,請檢查您的輸入!");
			}
		}
		//加密與解密文件
		public static void EncryptFile(int choice ,String inName, String outName ,byte[]Key,byte[]IV)
		{  
			try
			{
				//Create the file streams to handle the input and output files.
				FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
				FileStream fout = new FileStream(outName, FileMode.Append, FileAccess.Write);
				fout.SetLength(0); 
				byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
				long rdlen = 0;              //This is the total number of bytes written.
				long totlen = fin.Length;    //This is the total length of the input file.
				int len;			//This is the number of bytes to be written at a time. 

				crypt = SymmetricAlgorithm.Create(sma[choice]);
				
				CryptoStream encStream = new CryptoStream(fout,crypt.CreateEncryptor(Key,IV), CryptoStreamMode.Write);          
				//Read from the input file, then encrypt and write to the output file.
				while(rdlen < totlen)
				{
					len = fin.Read(bin, 0, 100);
					encStream.Write(bin, 0, len);
					rdlen = rdlen + len;
				}
				encStream.Close();
				fout.Close();
				fin.Close();						
			}
			catch
			{
				throw new CryptographicException("加密文件流時,出現錯誤,請檢查您的輸入!");
			}
		}
		//重寫這部分,因為使用上有些問題
		public static byte [] EncryptFile(int choice,string filename,byte[]Key,byte[]IV)
		{
			FileStream fs = new FileStream(filename,FileMode.Open,FileAccess.Read);
			byte []fileContent = new byte[fs.Length];	
			fs.Read( fileContent ,0,(int)fs.Length); //這樣限制了文件的長度啦!
			fs.Close();

			crypt = SymmetricAlgorithm.Create(sma[choice]);
			MemoryStream ms = new MemoryStream();	
			CryptoStream cs = new CryptoStream(ms,crypt.CreateEncryptor(Key,IV), CryptoStreamMode.Write);  
			cs.Write(fileContent,0,fileContent.Length);
			cs.FlushFinalBlock();
			return ms.ToArray();
		}
		//對文件的數據進行加密
		public static byte [] EncryptFile(int choice,byte[]fileContent,byte[]Key,byte[]IV)
		{
			crypt = SymmetricAlgorithm.Create(sma[choice]);
			MemoryStream ms = new MemoryStream();	
			CryptoStream cs = new CryptoStream(ms,crypt.CreateEncryptor(Key,IV), CryptoStreamMode.Write);  
			cs.Write(fileContent,0,fileContent.Length);
			cs.FlushFinalBlock();
			return ms.ToArray();
		}
		//解密方案失誤,經過修改,需要測試
		public static void DecryptFile( int choice,String inName, String outName ,byte[]Key,byte[]IV)
		{ 
			try
			{
				FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
				FileStream fout = new FileStream(outName, FileMode.Append, FileAccess.Write);
				fout.SetLength(0);  
				byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
				long rdlen = 0;              //This is the total number of bytes written.
				long totlen = fin.Length;    //This is the total length of the input file.
				int len;                     //This is the number of bytes to be written at a time.  
       
				crypt = SymmetricAlgorithm.Create(sma[choice]);
				
				CryptoStream encStream = new CryptoStream(fout,crypt.CreateDecryptor(Key,IV), CryptoStreamMode.Write); //已經改動  
				while(rdlen < totlen)
				{
					len = fin.Read(bin,0,100);
					encStream.Write(bin,0,len);
					rdlen = rdlen + len ;
				}
				encStream.Close();	
				fout.Close();
				fin.Close();
			}
			catch
			{
				throw new CryptographicException("解密文件流時,出現錯誤,請檢查您的輸入!");
			}
		}

		//重寫解密這部分
		public static byte [] DecryptFile(int choice,byte[]fileContent,byte[]Key,byte[]IV)
		{
			crypt = SymmetricAlgorithm.Create(sma[choice]);
			MemoryStream ms = new MemoryStream();	
			CryptoStream cs = new CryptoStream(ms,crypt.CreateDecryptor(Key,IV), CryptoStreamMode.Write);  
			cs.Write(fileContent,0,fileContent.Length);
			cs.FlushFinalBlock();
			return ms.ToArray();
		}
		// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		//簽名函數
		//直接簽名的函數 //需要導入鑰匙,當利用到鑰匙容器,不再需要直接導入鑰匙,需要再填寫一個函數
		private static RSACryptoServiceProvider icrypt ;//全局函數
		//簽名函數
		private static byte[] Signature( byte[] data )
		{			
			byte [] signature = icrypt.SignData(data,0,data.Length,MD5.Create() );//采用MD5格式簽名
			return signature;
		}
		//產生事例
		public static void SetInstance()
		{
			 icrypt = new RSACryptoServiceProvider();
		}
		//從外部導入鑰匙,密和私的鑰匙
		public static string XmlString(bool pub)
		{
		//	SetInstance();
			return icrypt.ToXmlString( pub );
		}
		private static void Key_FromXmlString( string rsakey )
		{		 
			try
			{
				icrypt.FromXmlString( rsakey );
			}
			catch
			{
				MessageBox.Show("導入鑰匙失敗!");
			}
				
		}
		//可以在外部直接引用這個函數
		//下面為簽名與驗證函數
		//簽名函數,為數據data簽名
		public static byte [] Sinature(string PriKeyXmlPath,byte[] data)
		{
	    	SetInstance();
			try
			{
				Key_FromXmlString( ReadXmlKey( PriKeyXmlPath ) ); //導入私鑰
			}
			catch
			{
				MessageBox.Show("導入私鑰失敗,請檢查原因!");
			}
			return icrypt.SignData(data,0,data.Length,MD5.Create());
		}
		//驗證簽名數據,公鑰驗證簽名,signedata為已經簽名的數據,tosigndata為要要驗證的簽名數據
		public static bool VerifySignature( string PubKeyXmlPath ,byte[]signedata,byte [] tosigndata )//,string publickey ) //RSAParameters DSAKeyInfo)
		{
			bool VerifyResult = false;
 			SetInstance();
			try
			{
				Key_FromXmlString( ReadXmlKey( PubKeyXmlPath ) ); //導入公鑰
			}
			catch
			{
				MessageBox.Show("導入公鑰失敗,請檢查原因!");
			}
			try
			{
				VerifyResult = icrypt.VerifyData( signedata,MD5.Create(), tosigndata);	
			}
			catch //(CryptographicException e)
			{
			}
			return VerifyResult;
		}
		//下面為使用公鑰加密數據,私鑰解密數據
		//使用公鑰加密數據
		public static byte [] RsaEncrypt(string PubKeyXmlPath ,byte [] bytes)
		{
			try
			{
				Key_FromXmlString( ReadXmlKey( PubKeyXmlPath ) ); //導入公鑰
			}
			catch
			{
				MessageBox.Show("導入公鑰失敗,請檢查原因!");
			}
			MemoryStream ms=new MemoryStream();
			int blockSize=0;
			if(icrypt.KeySize==1024)
				blockSize=16;
			else 
				blockSize=8;			
			byte[]rawblock,encryblock;
			for(int i=0;i<bytes.Length;i+=blockSize)
			{
				if((bytes.Length-i)>blockSize)
					rawblock=new byte[blockSize];
				else
					rawblock =new byte[bytes.Length-i];

				Buffer.BlockCopy(bytes,i,rawblock,0,rawblock.Length);

				encryblock=icrypt.Encrypt(rawblock,false);
				ms.Write(encryblock,0,encryblock.Length);
			}			
			ms.Position=0;
			byte [] encode=new byte[ms.Length];
			ms.Read(encode,0,(int)ms.Length);
    		ms.Close();           
			return encode;	
		}
		//使用私鑰解密(公鑰加密的數據)
		public static byte [] RsaDecrypt(string PriKeyXmlPath ,byte [] bytes)
		{
			SetInstance();
			try
			{
				Key_FromXmlString( ReadXmlKey( PriKeyXmlPath ) ); //導入私鑰
			}
			catch
			{
				MessageBox.Show("導入私鑰失敗,請檢查原因!");
			}
			MemoryStream ms=new MemoryStream();
			int keySize=icrypt.KeySize/8;
			byte[]rawblock,decryptblock;
			for(int i=0;i<bytes.Length;i+=keySize)
			{
				if( ( bytes.Length-i ) > keySize )
				{
					rawblock=new byte[keySize];
				}
				else
				{
					rawblock =new byte[bytes.Length-i];
				}
				Buffer.BlockCopy(bytes,i,rawblock,0,rawblock.Length);
				//問題的所在的地方,要注意查找其真實原因!!!!!!!!!!!!
				decryptblock = icrypt.Decrypt( rawblock,false );
				ms.Write(decryptblock,0,decryptblock.Length);
			}
			ms.Position=0;
			byte [] decode=new byte[ms.Length];
			ms.Read(decode,0,(int)ms.Length);
		 	ms.Close();
			return decode ;//icrypt.Encrypt( data,false );
			
		}
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//合并兩個數組或者三個數組
		//把第1個數組插接到第2個數組的后面。
		public static byte [] CombinBytes(byte[]dataone,byte[]datatwo)
		{
			MemoryStream ms =new MemoryStream();
			ms.Write(datatwo,0,datatwo.Length);
			ms.Write(dataone,0,dataone.Length);
			ms.Position = 0 ;
			return ms.ToArray();
		}
		//寫文件
		public static void WriteFile( string filepath,byte[]RsaEncryptData)
		{
			FileStream fs = new FileStream(filepath,FileMode.Append,FileAccess.Write);
			fs.Write(RsaEncryptData,0,RsaEncryptData.Length);
			fs.Flush();
			fs.Close();
		}
		private static string ReadXmlKey(string path)
		{
			string XmlKey;
			try
			{
				StreamReader sr = new StreamReader(path);
				XmlKey = sr.ReadToEnd();
				sr.Close();
			}
			catch
			{
				XmlKey = null ;
				MessageBox.Show("讀取文件失敗,請檢查原因!");			
			}
			return XmlKey ;
		}
		
		public static string OpenFile(string title)
		{
			OpenFileDialog open = new OpenFileDialog();
			open.Title =  title ;// "請打開你要產生摘要的文件:";
			open.Filter = "All File (*.*)|*.*";
			string FilePath = null ;
			if(open.ShowDialog()==DialogResult.OK)
			{	
				FilePath = open.FileName ;
			}
			return FilePath ;
		}
		
		public static void CreateXmlKey(string path,string key)
		{
			StreamWriter sw = new StreamWriter(path);
			sw.Write( key );
			sw.Flush();
			sw.Close();
		}
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成人午夜视频| 久久疯狂做爰流白浆xx| 欧美tickling网站挠脚心| 成人app下载| 国产一本一道久久香蕉| 亚洲成国产人片在线观看| 日韩av不卡一区二区| 亚洲精品视频免费看| 久久精品在这里| 日韩欧美高清在线| 欧美揉bbbbb揉bbbbb| 91丨九色porny丨蝌蚪| 国产精品小仙女| 麻豆91在线播放免费| 日韩电影免费在线看| 亚洲精品欧美在线| 国产精品久久久久永久免费观看| 日韩免费视频一区| 亚洲妇女屁股眼交7| 国产精品久久久久三级| 精品成人佐山爱一区二区| 欧美高清激情brazzers| 欧美日韩一区高清| 一本大道久久a久久精品综合| 成人av免费在线观看| 韩国在线一区二区| 精品一区二区三区日韩| 麻豆中文一区二区| 久久精品久久综合| 免费视频一区二区| 日本欧美大码aⅴ在线播放| 亚洲一区二区在线播放相泽| 一区二区三区中文字幕电影 | 91福利国产精品| 99re热这里只有精品视频| 成人黄色av网站在线| 粉嫩蜜臀av国产精品网站| 丁香桃色午夜亚洲一区二区三区| 国产精品一二三四| 国产成人啪免费观看软件| 国产成人精品aa毛片| 国产美女一区二区三区| 国产尤物一区二区| 国产成人精品亚洲日本在线桃色| 国产麻豆精品视频| 风间由美一区二区av101| 成人免费福利片| 色偷偷成人一区二区三区91| 欧洲精品在线观看| 精品视频1区2区| 日韩一区二区三区四区| 精品久久五月天| 国产欧美日韩在线看| 国产精品天美传媒| 综合久久综合久久| 亚洲午夜久久久久久久久电影网| 天天综合天天做天天综合| 久久精品国产秦先生| 国产suv精品一区二区883| 91亚洲国产成人精品一区二区三| 欧美视频一区二区| 日韩欧美高清在线| 国产精品久久久一本精品 | 处破女av一区二区| 欧美一区二区三区精品| 成人激情免费视频| 日韩午夜av电影| 在线观看日韩精品| 国产欧美日韩另类一区| 欧美精品日日鲁夜夜添| 3atv一区二区三区| 日韩一区二区三免费高清| 日韩一区二区三区视频在线| 2024国产精品| 国产精品久久久久久久久免费桃花 | 日本一区中文字幕| 国产一区二区三区精品欧美日韩一区二区三区 | 午夜久久久久久| 国产一区91精品张津瑜| 91性感美女视频| 日韩免费看网站| 成人免费在线观看入口| 日韩国产一二三区| 99精品欧美一区二区蜜桃免费| 欧美喷潮久久久xxxxx| 久久精品亚洲一区二区三区浴池| 日韩理论电影院| 麻豆精品国产91久久久久久| 成人av网址在线观看| 666欧美在线视频| 久久精品一区二区三区不卡牛牛| 午夜影视日本亚洲欧洲精品| 国产成人精品免费一区二区| 欧美日韩不卡视频| 亚洲欧美区自拍先锋| 国产一区二区福利| 欧美一区二区三区免费在线看| 最近日韩中文字幕| 国产乱人伦精品一区二区在线观看| 欧美日韩一区高清| 亚洲欧美偷拍卡通变态| 欧美日韩电影在线播放| 最近日韩中文字幕| 国产成a人亚洲| 日韩一级二级三级| 一区二区三区四区五区视频在线观看| 精品一区二区三区日韩| 欧美男人的天堂一二区| 亚洲欧美日韩电影| 成人精品视频.| 久久久久久久综合日本| 丝袜亚洲另类欧美| 欧美唯美清纯偷拍| 亚洲激情网站免费观看| 99在线精品视频| 国产精品理伦片| 成人免费视频免费观看| 久久久99精品久久| 国产麻豆成人精品| 久久精品一区八戒影视| 精品一区二区日韩| 欧美www视频| 紧缚捆绑精品一区二区| 亚洲精品一区二区三区四区高清 | 91精品免费观看| 偷拍日韩校园综合在线| 欧美日韩一区二区三区在线 | 亚洲免费av网站| 97久久超碰国产精品| 亚洲图片欧美激情| av福利精品导航| 中文字幕制服丝袜成人av| 国产91在线|亚洲| 欧美激情在线看| 不卡视频免费播放| 国产精品久线观看视频| 成人听书哪个软件好| 国产精品国产精品国产专区不蜜| 国产69精品久久久久毛片| 成人欧美一区二区三区在线播放| 久久免费视频色| 国产精品影音先锋| 中文字幕精品综合| 99国产精品视频免费观看| 国产精品久久久久久久久免费相片 | 亚洲欧美成人一区二区三区| 97久久超碰精品国产| 一区二区国产盗摄色噜噜| 欧美群妇大交群的观看方式| 日韩av网站在线观看| 精品av综合导航| 成人免费毛片app| 一区二区三区资源| 欧美福利视频导航| 久久电影国产免费久久电影| 久久精品亚洲精品国产欧美kt∨| 国产·精品毛片| 亚洲免费观看在线观看| 欧美日韩另类国产亚洲欧美一级| 免费视频一区二区| 国产三区在线成人av| 91丨九色丨黑人外教| 丝袜亚洲精品中文字幕一区| 久久久久久久综合色一本| 91老师国产黑色丝袜在线| 日精品一区二区| 国产片一区二区| 欧美日韩另类国产亚洲欧美一级| 国内不卡的二区三区中文字幕| 中文字幕日韩欧美一区二区三区| 欧洲国产伦久久久久久久| 精品亚洲免费视频| 亚洲精品国产精华液| 欧美成人午夜电影| 色综合久久久网| 久久福利视频一区二区| 亚洲欧美日韩中文字幕一区二区三区| 在线播放中文字幕一区| 成人在线综合网| 爽好久久久欧美精品| 中文字幕在线观看一区二区| 欧美日韩国产123区| 成人高清免费观看| 日韩va欧美va亚洲va久久| 国产精品嫩草久久久久| 777精品伊人久久久久大香线蕉| 床上的激情91.| 六月婷婷色综合| 亚洲影院理伦片| 中文字幕av一区二区三区| 67194成人在线观看| 色综合视频一区二区三区高清| 久久国产剧场电影| 亚洲大片一区二区三区| 国产精品毛片久久久久久久| 欧美tickling挠脚心丨vk| 欧美日韩国产一级| 91视频xxxx| 成人av在线看| 国产精品一二三四区|