c#数据库密码保护问题?谢谢! 把密码加密以后再存入数据库 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以把密码用加密。.net中提供了几种现成的加密算法。在System.Security.Cryptography名字空间下,自己查查msdn嘛。这里有一段源码,使用的是Rijndael对称算法,希望有用:string file = args[0];string tempfile = Path.GetTempFileName();//打开指定的文件FileStream fsIn = File.Open(file,FileMode.Open,FileAccess.Read);FileStream fsOut = File.Open(tempfile, FileMode.Open,FileAccess.Write);//定义对称算法对象实例和接口SymmetricAlgorithm symm = new RijndaelManaged();ICryptoTransform transform = symm.CreateEncryptor();CryptoStream cstream = new CryptoStream(fsOut,transform,ryptoStreamMode.Write);BinaryReader br = new BinaryReader(fsIn);// 读取源文件到cryptostream cstream.Write(br.ReadBytes((int)fsIn.Length),0,(int)fsIn.Length);cstream.FlushFinalBlock();cstream.Close();fsIn.Close();fsOut.Close();Console.WriteLine("created encrypted file {0}", tempfile);Console.WriteLine("will now decrypt and show contents");// 反向操作--解密刚才加密的临时文件fsIn = File.Open(tempfile,FileMode.Open,FileAccess.Read);transform = symm.CreateDecryptor();cstream = new CryptoStream(fsIn,transform,CryptoStreamMode.Read);StreamReader sr = new StreamReader(cstream);Console.WriteLine("decrypted file text: " + sr.ReadToEnd());fsIn.Close(); 密码放在数据库中!但是要加密,建议使用不可逆的加密算法,例如MD5或你自己设计一个稀奇古怪的算法,只要保证生成的加密后的串在不同密码明文出现相同加密结果的几率足够小即可。验证时按照同样的算法生成加密串,与数据库中的保存的加密串比较即可,不用解密出密码原文(因为不存在逆向算法),可保证密码的安全。 分不是问题,上次我全给了,还有高手吗 求一思路 C#控件问题(急需各路大侠帮助!) 在WPF中如何实现托盘图标 关于汉字向Unicode的转换. 超级菜鸟,如何学好C# 调用外部获取到一个string格式的XML字符串,怎么将这个作为数据源绑定到Form界面上的控件上? 如何在屏幕任意位置直接输入字符? 谁能给个上传与下载的例子? Math.Round的疑惑 请问一个弱智级ADO.NET问题!进者又分 初学者请教一个问题,谢谢!
string file = args[0];
string tempfile = Path.GetTempFileName();
//打开指定的文件
FileStream fsIn = File.Open(file,FileMode.Open,
FileAccess.Read);
FileStream fsOut = File.Open(tempfile, FileMode.Open,
FileAccess.Write);
//定义对称算法对象实例和接口
SymmetricAlgorithm symm = new RijndaelManaged();
ICryptoTransform transform = symm.CreateEncryptor();
CryptoStream cstream = new CryptoStream(fsOut,transform,
ryptoStreamMode.Write);BinaryReader br = new BinaryReader(fsIn);
// 读取源文件到cryptostream
cstream.Write(br.ReadBytes((int)fsIn.Length),0,(int)fsIn.Length);
cstream.FlushFinalBlock();
cstream.Close();
fsIn.Close();
fsOut.Close();Console.WriteLine("created encrypted file {0}", tempfile);
Console.WriteLine("will now decrypt and show contents");// 反向操作--解密刚才加密的临时文件
fsIn = File.Open(tempfile,FileMode.Open,FileAccess.Read);
transform = symm.CreateDecryptor();
cstream = new CryptoStream(fsIn,transform,
CryptoStreamMode.Read);StreamReader sr = new StreamReader(cstream);
Console.WriteLine("decrypted file text: " + sr.ReadToEnd());
fsIn.Close();