给一份源码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Security.Cryptography;
using System.Data.SqlClient;
using System.IO.IsolatedStorage;
namespace OAOffice.Contract.upload
{
/// <summary>
/// enc 的摘要说明。
/// </summary>
public class enc : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
public byte[] _key;
public byte[] _iv;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
RijndaelManaged RMCrypto = new RijndaelManaged();
//ViewState.Add(key,RMCrypto.Key);
//ViewState.Add(iv,RMCrypto.IV);
_key = new byte[16];
_iv = new byte[16];
_key=RMCrypto.Key;
_iv=RMCrypto.IV;
ViewState.Add("key",_key);
ViewState.Add("iv",_iv);
//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.OpenOrCreate,FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write
byte[] bin = new byte[100]; //This is intermediate stroage for the encryption
long rdlen=0; //This is the total number fo 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.
RijndaelManaged des = new RijndaelManaged();
CryptoStream encStream = new CryptoStream(fout,des.CreateEncryptor(desKey,desIV),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();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
//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.OpenOrCreate,FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write
byte[] bin = new byte[100]; //This is intermediate stroage for the encryption
long rdlen=0; //This is the total number fo 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.
RijndaelManaged des = new RijndaelManaged();
CryptoStream encStream = new CryptoStream(fout,des.CreateDecryptor(desKey,desIV),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;