decrypting database.config

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
mike92117
Lieutenant (LT)
Lieutenant (LT)
Posts: 64
Joined: Sat Nov 07, 2009 6:41 pm

decrypting database.config

Post by mike92117 » Thu Nov 12, 2009 10:44 pm

I have several console applications that I'm developing to do various tasks. My usual approach to this is to read the web.config and get the conn string, that way when and if it changes, it won't break my existing console applications. My console apps have a configuration value of the file to read to get the conn string.

I want to do the same with my ac store, i.e., have my console applications read the database.config file in app_data. However, it is encrypted and I want to know what I need to do to decrypt it.

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: decrypting database.config

Post by jmestep » Fri Nov 13, 2009 6:35 am

You could store the connection string unencrypted in the global.asax file if you can code against it from there. Here's an example of doing it in one way, but you could put the whole connection string in as a string.
Found by Googling:

Code: Select all

Global.asax.cs

protected void Application_Start(Object sender, EventArgs e)
{
Application["DbUser"]="dbUser";
Application["DbUserPass"]="myPass";
Application["DbName"]="coolDB";
Application["DbServer"]="my.office.db.server";

string myConnString = "Data Source=" +
Application["DbServer"] + ";Initial Catalog=" +
Application["DbName"] + ";User ID=" +
Application["DbUser"] + ";Password=" +
Application["DbUserPass"];
Application["ConnString"] = myConnString;
} 
You could use Application["ConnString"]= (whole connection string here)
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: decrypting database.config

Post by mazhar » Fri Nov 13, 2009 6:37 am

Give a try and make use of CommerceBuilder.Utility.EncryptionHelper.DecryptAES method by providing it the ciphered string.

mike92117
Lieutenant (LT)
Lieutenant (LT)
Posts: 64
Joined: Sat Nov 07, 2009 6:41 pm

Re: decrypting database.config

Post by mike92117 » Fri Nov 13, 2009 6:03 pm

Thank you for your answers.

I actually found a super simple and very elegant way to accomplish this:

Code: Select all

VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(@"C:\www\myAbleCommerceSite", true);
WebConfigurationFileMap wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
string connStr = config.ConnectionStrings.ConnectionStrings["AbleCommerce"].ConnectionString;

Post Reply