如何保存配置信息?

essenza 2008-09-08 10:02:05
数据库连接的ip,用户,密码等不能写死在程序里面,但是用配置文件又不安全,能否提供一个比较安全的解决办法?
加密解密的代码?
...全文
209 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
想飞的狼 2008-09-09
  • 打赏
  • 举报
回复
楼上的对,用这个方法是最安全的
tangweikai 2008-09-09
  • 打赏
  • 举报
回复
使用[应用程序配置文件],微软已经为你处理好的安全问题:
在 my.settings中增加一个 MyConnectionString
操作就是读写和储存:My.Settings.MyConnectionString,非常简单.
ejoe313 2008-09-09
  • 打赏
  • 举报
回复
或者加密后保存在注册表里
dengzebo 2008-09-09
  • 打赏
  • 举报
回复
//给分!结贴
using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;
namespace Bozhai.Class
{
public class StringOption
{

#region "变量定义"
private SymmetricAlgorithm mCSP;
private const string CIV = "kXwL7X2+fgM=";//密钥
private const string CKEY = "FwGQWRRgKCI=";//初始化向量
#endregion

#region "实例化"
public StringOption()
{
Bozhai.Class.SoftVerReg BC=new SoftVerReg();
if(BC.GetRegInf() == false)
{
System.Windows.Forms.MessageBox.Show("您使用了未注册的版本组件:Bozhai.Class.StringOption.dll,请注册后使用!", "组件注册:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}
mCSP = new DESCryptoServiceProvider();
}
#endregion

#region "加密"
public string EncryptString(string Value)
{
ICryptoTransform ct;
MemoryStream ms;
CryptoStream cs;
byte[] byt;

ct = mCSP.CreateEncryptor(Convert.FromBase64String(CKEY), Convert.FromBase64String(CIV));

byt = Encoding.UTF8.GetBytes(Value);

ms = new MemoryStream();
cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();

cs.Close();

return Convert.ToBase64String(ms.ToArray());
}
#endregion

#region "解密"
public string DecryptString(string Value)
{
ICryptoTransform ct;
MemoryStream ms;
CryptoStream cs;
byte[] byt;

ct = mCSP.CreateDecryptor(Convert.FromBase64String(CKEY), Convert.FromBase64String(CIV));

byt = Convert.FromBase64String(Value);

ms = new MemoryStream();
cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();

cs.Close();

return Encoding.UTF8.GetString(ms.ToArray());
}
#endregion
}

}
yagebu1983 2008-09-09
  • 打赏
  • 举报
回复
放在配置文件里就醒了!!
你对节点加密也可以!!
liuyun1987 2008-09-09
  • 打赏
  • 举报
回复
汗。。放在web.config里还不够安全?
fairy4 2008-09-09
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cauhorse 的回复:]
标记下,过两天就得用到了。。
[/Quote]
cauhorse 2008-09-09
  • 打赏
  • 举报
回复
标记下,过两天就得用到了。。
zjw2004112 2008-09-08
  • 打赏
  • 举报
回复
就放在web.cofig里呀,在对webcofig加密,还有什么不安全的,
brallow 2008-09-08
  • 打赏
  • 举报
回复
参考这里的几个方案,都可以。
http://www.cnblogs.com/9who/archive/2008/07/28/1254526.html
http://www.cnblogs.com/xiaoxijin/archive/2007/06/17/786068.html
http://topic.csdn.net/t/20060328/08/4644373.html

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧