日期:2014-05-17  浏览次数:20517 次

加密连接字符串遇到的问题!
这是我在网上COPY的一个方法

 public static void EncryptConfiguration()
  {
  string provider = "RsaProtectedConfigurationProvider";
  Configuration config = null;
  config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

  ConfigurationSection section = config.ConnectionStrings;
  if ((section.SectionInformation.IsProtected == false) && (section.SectionInformation.IsLocked == false))
  {
  section.SectionInformation.ProtectSection(provider);
  section.SectionInformation.ForceSave = true;
  config.Save(ConfigurationSaveMode.Full);
  }
  }

我用的是asp.net ,当我在主页面的LOAD的里调用次方法时,会发生这样的错误 "当不在独立 exe 内部运行时,必须指定 exePath”
想请问下高手我该怎么解决这个问题?有没有更好的加密连接字符串的方法?谢拉!

------解决方案--------------------
C# code

public string getMd5str(string str, string privatestr)
        {
            string inputString = str + privatestr;
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(inputString));
            return BitConverter.ToString(result).Replace("-", "");
        }

------解决方案--------------------
.net好像有自带的加密连接字符串的方法
以前见过 忘啦
呵呵 找找看
楼上的 你的加密是md5加密
加密 密码还可以

------解决方案--------------------
OpenExeConfiguration(ConfigurationUserLevel.None)这个用于winform程序,你应该搜一下“asp.NET怎么修改配置文件”
------解决方案--------------------
vs.net有安全的类,有很多加密的方法,
------解决方案--------------------
http://shanyou.cnblogs.com/archive/2006/02/08/327196.aspx