public class BaseController : Controller { ////// 用户中心Dbhelper /// public IDbHelper DbHelperUserCenter = GetDbConnection(BaseSystemInfo.UserCenterDbType, BaseSystemInfo.UserCenterDbConnection, ConfigHelper.GetConfigBool("BusinessDbEncrypt")); ////// 业务库Dbhelper /// public IDbHelper DbHelperBusiness = GetDbConnection(BaseSystemInfo.BusinessDbType, BaseSystemInfo.BusinessDbConnection, ConfigHelper.GetConfigBool("UserCenterDbEncrypt")); ////// 获得DbHelper /// /// 数据库类别 /// 连接字符串 /// 是否加密 ///IDbHelper private static IDbHelper GetDbConnection(CurrentDbType currentDbType, string dbConnection, bool dbEncrypt = false) { if (dbEncrypt) { dbConnection= SecretUtil.Decrypt(dbConnection); } return DbHelperFactory.GetHelper(currentDbType, dbConnection); }..........}
这里是mvc中基类的写法,其中提供了数据库使用加密方式后的解密方法。