如题。看了半天MSDN也没明白,好象举的例都是字符串。
解决方案 »
- silverlight 实现类似word的特殊字符输入工具
- dataset的select里能求比吗?
- vs2010GDI命名空间
- C# 如何在DataGridView中的DataGridViewTextBoxColumn列添加鍵盤降響應
- 定时程序的问题
- ArrayList如何改变某一项的值?
- 在VISUAL Studio 中这种按钮是用什么做出来的?
- 虚拟主机 服务器选择Win2000好呢,还是Win2003好(放置asp.net程序)
- LISTVIEW
- dataset的一个常见问题
- 求助:如何将string 类转换为Color类型?
- 求救:我原来有VS2003做的项目,可以编绎,没有错误,可换用VS2005打开编绎,就出现这样的错误,而且编绎不成功呀!这是乍的啦?
解密的时候再减1算是加密解密么
对字符串加密也是转化到byte数组中,然后对byte数组进行加密。对文件加密的话,可以将文件读入到byte数组中,然后加密后
RijndaelManaged aes = new RijndaelManaged();
aes.GenerateKey();
aes.GenerateIV();
//加密
FileStream fs = new FileStream("1.jpg",FileMode.Open,FileAccess.Read);
byte[] contains = new byte[fs.Length];
fs.Read(contains, 0, (int)fs.Length);
MemoryStream ms = new MemoryStream();
CryptoStream cts = new CryptoStream(ms,aes.CreateEncryptor(aes.Key,aes.IV), CryptoStreamMode.Write);
cts.Write(contains, 0, (int)fs.Length);
cts.FlushFinalBlock();
cts.Close();
byte[] encreptData = ms.ToArray();
FileStream fs2 = new FileStream("e.jpg",FileMode.Create,FileAccess.Write);
fs2.Write(encreptData, 0, encreptData.Length);
fs2.Flush();
fs2.Close(); //解密
FileStream fs3 = new FileStream("e.jpg",FileMode.Open, FileAccess.Read);
byte[] contains2 = new byte[fs3.Length];
fs3.Read(contains2, 0, (int)fs3.Length);
ms = new MemoryStream(contains2);
cts = new CryptoStream(ms, aes.CreateDecryptor(aes.Key, aes.IV), CryptoStreamMode.Read);
byte[] decryptData = new byte[fs3.Length];
cts.Read(decryptData, 0, (int)fs3.Length);
cts.Close();
FileStream fs4 = new FileStream("d.jpg",FileMode.OpenOrCreate,FileAccess.Write);
fs4.Write(decryptData, 0, decryptData.Length);
fs4.Flush();
fs3.Close();
fs4.Close();