【发布时间】:2014-09-15 11:27:50
【问题描述】:
我想在 Entity Framework 5 中使用它时对连接字符串进行加密和解密。
我做了什么,我的连接字符串是
<add name="HContext" connectionString="Data Source=(localdb)\Projects;Initial Catalog=MyDBName;Integrated Security=True;" providerName="System.Data.SqlClient" />
我已经在下面加密了这个连接
string encryptedString = KimberlyClark.EuroCRM.Encryption.Encrypt(encryptedString, "mykey");
之后,我将加密字符串复制到我的 web.config 文件中并像下面这样使用
public class HContext : DbContext
{
public HContext()
: base("HContext")
{
string encryptedString = System.Configuration.ConfigurationManager.ConnectionStrings["HContext"].ConnectionString;
string connectString = KimberlyClark.EuroCRM.Encryption.Decrypt(encryptedString, "mykey");
Database.Connection.ConnectionString = connectString;
}
}
但我在构造函数中遇到错误
初始化字符串的格式不符合从索引 0 开始的规范
谢谢
【问题讨论】:
标签: asp.net-mvc-4 c#-4.0 encryption entity-framework-5