对txt文档的读取加密存储 解密读取 我是个c#新手 在写个后台对新闻管理对txt文档的读取加密存储 解密读取 我知道用FileStream 类 读取 用MD5CryptoServiceProvider类加密 但写了很多次老是整部队 想写成一个类 传入一个路径 请各位帮我写下 谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 MD5是散列算法,不是加密。简单点,你用对称密钥加解密(就是加密、和解密都是同一个对密钥)。在计算机专网系统中广泛使用的对称加密算法有DES和IDEA等。美国国家标准局倡导的AES即将作为新标准取代DES。 具体算法: 3DES算法,Blowfish算法,RC5算法。比如:RC2CryptoServiceProvider RijndaelManaged TripleDESCryptoServiceProvider //例加密文本文件(RijndaelManaged ) byte[] key = { 24, 55, 102,24, 98, 26, 67, 29, 84, 19, 37, 118, 104, 85, 121, 27, 93, 86, 24, 55, 102, 24,98, 26, 67, 29, 9, 2, 49, 69, 73, 92 }; byte[] IV ={ 22, 56, 82, 77, 84, 31, 74, 24,55, 102, 24, 98, 26, 67, 29, 99 }; RijndaelManaged myRijndael = new RijndaelManaged(); FileStream fsOut = File.Open(strOutName, FileMode.Create,FileAccess.Write);//strOutName文件名及路径 FileStream fsIn = File.Open(strPath, FileMode.Open,FileAccess.Read); CryptoStream csDecrypt=new CryptoStream(fsOut,myRijndael.CreateEncryptor(key, IV),CryptoStreamMode.Write);//读加密文本 BinaryReader br = new BinaryReader(fsIn); csDecrypt.Write(br.ReadBytes((int)fsIn.Length),0, (int)fsIn.Length); csDecrypt.FlushFinalBlock(); csDecrypt.Close(); fsIn.Close(); fsOut.Close(); //解密文件 byte[] key = { 24, 55, 102, 24, 98, 26, 67, 29, 84, 19, 37, 118,104, 85, 121, 27, 93, 86, 24, 55, 102, 24, 98, 26, 67, 29, 9, 2, 49, 69, 73, 92}; byte[] IV ={ 22, 56, 82, 77, 84, 31, 74, 24, 55, 102, 24, 98, 26,67, 29, 99 }; RijndaelManaged myRijndael = new RijndaelManaged(); FileStream fsOut = File.Open(strPath, FileMode.Open, FileAccess.Read); CryptoStream csDecrypt = new CryptoStream(fsOut, myRijndael.CreateDecryptor(key,IV), CryptoStreamMode.Read); StreamReader sr = new StreamReader(csDecrypt);//把文件读出来 StreamWriter sw = new StreamWriter(strInName);//解密后文件写入一个新的文件 sw.Write(sr.ReadToEnd()); sw.Flush(); sw.Close(); sr.Close();f sOut.Close();复杂点,你可以用非对称密钥加解密(就是加密、和解密都是用不同的2对密钥)。比如:RSA,ECC等。 已知一个非对称矩阵的特征值,编写C#求出该矩阵的特征向量 输出“金字塔”形的杨辉三角。 急!有人用过 Lassalle.Flow 吗? vs2005 C#中,怎样在自己的程序中生成VRMap的场景? 怎么样把res和il编译成dll 求助大神帮忙呀。 C#中list.Sort()自定义排序问题 求datagrid中如何删除一列 不用存数据库的,请各位帮小弟写出方法 关于动态生成控件的事件添加问题 [100分求助]执行这段代码出现系统异常 如何在VS2005里生成C#的com组件供ASP使用 上传txt文本文件,按行读取,存入数据库,怎么办呢??求教高手
在计算机专网系统中广泛使用的对称加密算法有DES和IDEA等。美国国家标准局倡导的AES即将作为新标准取代DES。
具体算法:
3DES算法,Blowfish算法,RC5算法。比如:
RC2CryptoServiceProvider
RijndaelManaged
TripleDESCryptoServiceProvider
//例加密文本文件(RijndaelManaged )
byte[] key = { 24, 55, 102,24, 98, 26, 67, 29, 84, 19, 37, 118, 104, 85, 121, 27, 93, 86, 24, 55, 102, 24,98, 26, 67, 29, 9, 2, 49, 69, 73, 92 };
byte[] IV ={ 22, 56, 82, 77, 84, 31, 74, 24,55, 102, 24, 98, 26, 67, 29, 99 };
RijndaelManaged myRijndael = new RijndaelManaged();
FileStream fsOut = File.Open(strOutName, FileMode.Create,FileAccess.Write);//strOutName文件名及路径 FileStream fsIn = File.Open(strPath, FileMode.Open,FileAccess.Read);
CryptoStream csDecrypt=new CryptoStream(fsOut,myRijndael.CreateEncryptor(key, IV),CryptoStreamMode.Write);//读加密文本
BinaryReader br = new BinaryReader(fsIn);
csDecrypt.Write(br.ReadBytes((int)fsIn.Length),0, (int)fsIn.Length);
csDecrypt.FlushFinalBlock();
csDecrypt.Close();
fsIn.Close();
fsOut.Close();
//解密文件
byte[] key = { 24, 55, 102, 24, 98, 26, 67, 29, 84, 19, 37, 118,104, 85, 121, 27, 93, 86, 24, 55, 102, 24, 98, 26, 67, 29, 9, 2, 49, 69, 73, 92};
byte[] IV ={ 22, 56, 82, 77, 84, 31, 74, 24, 55, 102, 24, 98, 26,67, 29, 99 };
RijndaelManaged myRijndael = new RijndaelManaged();
FileStream fsOut = File.Open(strPath, FileMode.Open, FileAccess.Read);
CryptoStream csDecrypt = new CryptoStream(fsOut, myRijndael.CreateDecryptor(key,IV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(csDecrypt);//把文件读出来
StreamWriter sw = new StreamWriter(strInName);//解密后文件写入一个新的文件
sw.Write(sr.ReadToEnd());
sw.Flush();
sw.Close();
sr.Close();f
sOut.Close();
复杂点,你可以用非对称密钥加解密(就是加密、和解密都是用不同的2对密钥)。比如:RSA,ECC等。