473,769 Members | 7,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Encrypted and Decrypted Conn String Programatically

Hi,

I have a question about encrypting connection strings in an asp.net 2.0
app in a shared hosting environment. From what I have read, I believe
I need to programatically encrypt and decrypt the conn string because I
do not have access to run aspnet_regiis on the remote machine.

My question is where to do I put the code?
Do I first encrypt the connection string on page_load, and then every
time I need to access the database decrypt the code? How do I start
with the conn string encoded, and then decrypt it only when needed.
There is a great sample by David Hayden and I understand the concept, I
just don't know where to "put" everything.
(http://davidhayden.com/blog/dave/arc...1/17/2572.aspx)

Thanks in advance!
-David

Nov 25 '06 #1
5 2453

"Ranginald" <da*******@gmai l.comwrote in message
news:11******** *************@4 5g2000cws.googl egroups.com...
Hi,

I have a question about encrypting connection strings in an asp.net 2.0
app in a shared hosting environment. From what I have read, I believe
I need to programatically encrypt and decrypt the conn string because I
do not have access to run aspnet_regiis on the remote machine.

My question is where to do I put the code?
Do I first encrypt the connection string on page_load, and then every
time I need to access the database decrypt the code? How do I start
with the conn string encoded, and then decrypt it only when needed.
There is a great sample by David Hayden and I understand the concept, I
just don't know where to "put" everything.
(http://davidhayden.com/blog/dave/arc...1/17/2572.aspx)

Thanks in advance!
-David
You have aspnet_regiis on every machine that has the .net framework
installed.

You don't need to encrypt & decrypt programatically as that happens
automagically by the framework. Just encrypt it once during installation
with aspnet_regiis and forget about it.

You can't encrypt the web.config during development and ship that one
because its specific to a machines private keys.
Nov 25 '06 #2
If I encrypt it with aspnet_regiis on my local machine, how do I
decrypt it on the production (shared hosting server)? e.g. When is
"installati on"?

I read a Iot about the topic before I posted and I thought I had to
have access to aspnet_regiis on the remote machine in order to use
aspnet_regiis.. ..something about copying the keys to the remote server.

If I encrypt it locally as you say using aspnet_regiis, do I use RSA or
DPAPI?

Thanks,
David

(nice use of "automagically" )

"Ranginald" <da*******@gmai l.comwrote in message
news:11******** *************@4 5g2000cws.googl egroups.com...
Hi,

I have a question about encrypting connection strings in an asp.net 2.0
app in a shared hosting environment. From what I have read, I believe
I need to programatically encrypt and decrypt the conn string because I
do not have access to run aspnet_regiis on the remote machine.

My question is where to do I put the code?
Do I first encrypt the connection string on page_load, and then every
time I need to access the database decrypt the code? How do I start
with the conn string encoded, and then decrypt it only when needed.
There is a great sample by David Hayden and I understand the concept, I
just don't know where to "put" everything.
(http://davidhayden.com/blog/dave/arc...1/17/2572.aspx)

Thanks in advance!
-David

You have aspnet_regiis on every machine that has the .net framework
installed.

You don't need to encrypt & decrypt programatically as that happens
automagically by the framework. Just encrypt it once during installation
with aspnet_regiis and forget about it.

You can't encrypt the web.config during development and ship that one
because its specific to a machines private keys.
Nov 25 '06 #3

"Ranginald" <da*******@gmai l.comwrote in message
news:11******** **************@ h54g2000cwb.goo glegroups.com.. .
If I encrypt it with aspnet_regiis on my local machine, how do I
decrypt it on the production (shared hosting server)? e.g. When is
"installati on"?

I read a Iot about the topic before I posted and I thought I had to
have access to aspnet_regiis on the remote machine in order to use
aspnet_regiis.. ..something about copying the keys to the remote server.

If I encrypt it locally as you say using aspnet_regiis, do I use RSA or
DPAPI?

Thanks,
David

(nice use of "automagically" )

>"Ranginald" <da*******@gmai l.comwrote in message
news:11******* **************@ 45g2000cws.goog legroups.com...
Hi,

I have a question about encrypting connection strings in an asp.net 2.0
app in a shared hosting environment. From what I have read, I believe
I need to programatically encrypt and decrypt the conn string because I
do not have access to run aspnet_regiis on the remote machine.

My question is where to do I put the code?
Do I first encrypt the connection string on page_load, and then every
time I need to access the database decrypt the code? How do I start
with the conn string encoded, and then decrypt it only when needed.
There is a great sample by David Hayden and I understand the concept, I
just don't know where to "put" everything.
(http://davidhayden.com/blog/dave/arc...1/17/2572.aspx)

Thanks in advance!
-David

You have aspnet_regiis on every machine that has the .net framework
installed.

You don't need to encrypt & decrypt programatically as that happens
automagicall y by the framework. Just encrypt it once during installation
with aspnet_regiis and forget about it.

You can't encrypt the web.config during development and ship that one
because its specific to a machines private keys.
I meant: you run aspnet_regiis on the server as part of the process of
"copying the website over to the production server". Once you've copied
everything over to your production server you run aspnet_regiis ON THE
SERVER and the web.config is encrypted using that machines private keys, so
it wont be able to be read on any other machine.

You should be putting your connection strings in the
"connectionStri ngs" section in your web.config. Now, in your code, when you
want to access it, you access it like so:

SqlConnection sqlCon = new
SqlConnection(C onfigurationMan ager.Connection Strings["cstrDataba se"].ToString());

thats it... no encryption, decryption is necessary on your part as it all
happens "automagically" ... of course as I said earlier, if you copy an
encrypted web.config to another machine, it will no longer work. Its
encrypted per machine.


Nov 25 '06 #4
Right...but the whole problem is that I can't run aspnet_regiis on the
server.......it 's shared hosting.
Nobody wrote:
"Ranginald" <da*******@gmai l.comwrote in message
news:11******** **************@ h54g2000cwb.goo glegroups.com.. .
If I encrypt it with aspnet_regiis on my local machine, how do I
decrypt it on the production (shared hosting server)? e.g. When is
"installati on"?

I read a Iot about the topic before I posted and I thought I had to
have access to aspnet_regiis on the remote machine in order to use
aspnet_regiis.. ..something about copying the keys to the remote server.

If I encrypt it locally as you say using aspnet_regiis, do I use RSA or
DPAPI?

Thanks,
David

(nice use of "automagically" )

"Ranginald" <da*******@gmai l.comwrote in message
news:11******** *************@4 5g2000cws.googl egroups.com...
Hi,

I have a question about encrypting connection strings in an asp.net 2.0
app in a shared hosting environment. From what I have read, I believe
I need to programatically encrypt and decrypt the conn string because I
do not have access to run aspnet_regiis on the remote machine.

My question is where to do I put the code?
Do I first encrypt the connection string on page_load, and then every
time I need to access the database decrypt the code? How do I start
with the conn string encoded, and then decrypt it only when needed.
There is a great sample by David Hayden and I understand the concept, I
just don't know where to "put" everything.
(http://davidhayden.com/blog/dave/arc...1/17/2572.aspx)

Thanks in advance!
-David


You have aspnet_regiis on every machine that has the .net framework
installed.

You don't need to encrypt & decrypt programatically as that happens
automagically by the framework. Just encrypt it once during installation
with aspnet_regiis and forget about it.

You can't encrypt the web.config during development and ship that one
because its specific to a machines private keys.

I meant: you run aspnet_regiis on the server as part of the process of
"copying the website over to the production server". Once you've copied
everything over to your production server you run aspnet_regiis ON THE
SERVER and the web.config is encrypted using that machines private keys, so
it wont be able to be read on any other machine.

You should be putting your connection strings in the
"connectionStri ngs" section in your web.config. Now, in your code, when you
want to access it, you access it like so:

SqlConnection sqlCon = new
SqlConnection(C onfigurationMan ager.Connection Strings["cstrDataba se"].ToString());

thats it... no encryption, decryption is necessary on your part as it all
happens "automagically" ... of course as I said earlier, if you copy an
encrypted web.config to another machine, it will no longer work. Its
encrypted per machine.
Nov 25 '06 #5
"Ranginald" <da*******@gmai l.comwrote in message
news:11******** **************@ h54g2000cwb.goo glegroups.com.. .
Right...but the whole problem is that I can't run aspnet_regiis on the
server.......it 's shared hosting.
Nobody wrote:
<snip>

you can encrypt the sections programatically too... but you don't need to
encrypt/decrypt to read the settings, you just need to encrypt it once and
be done...

Here is some code (although it works on the appSettings portion)...

// open the configuration manager

Configuration config =
WebConfiguratio nManager.OpenWe bConfiguration( HostingEnvironm ent.Application VirtualPath);

// get the appSettings section

ConfigurationSe ction section = config.GetSecti on("appSettings ");

// create the appSettings section if it doesn't exist

if (section == null)
{
section = new AppSettingsSect ion();
config.Sections .Add("appSettin gs", section);
bDirty = true;
}

// cast to the appSettings type

AppSettingsSect ion appSettings = (AppSettingsSec tion)section;

// attempt to read the private key

string strKey = appSettings.Set tings["privateKey "].Value;

// create the key if it doesn't exist

if (strKey == null)
{
TripleDESCrypto ServiceProvider alg = new
TripleDESCrypto ServiceProvider ();
strKey = Convert.ToBase6 4String(alg.Key );
appSettings.Set tings.Add("priv ateKey", strKey);
bDirty = true;
}

// protect the section if it isn't already protected

if (!section.Secti onInformation.I sProtected)
{
section.Section Information.Pro tectSection("Rs aProtectedConfi gurationProvide r");
bDirty = true;
}

if (bDirty)
config.Save();

return strKey;
}
Nov 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4475
by: Todd Gruben | last post by:
I am trying to send some encrypted data from a php application to be decoded in a .Net application. Both apps encode/decode a given string but generate different encrypted results. Anyone have any idea? Code to follow: php====> <?php // Designate string to be encrypted $string = "This is a test";
2
5138
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do this kind of communication in a secure way (protected from sniffing)? It would be a very simple protocol. Question, and two possible answers 'yes' or 'no'.
0
1013
by: Li Pang | last post by:
Hi, My inbox receives regularly the encrypted emails. I made a small app by using outlook activeX to read the emails (decrypted by outlook). I just want to know if outlook application provides a method to tell me that an email was encrypted, or it was decrypted from an encrypted one, some thing like IsEncrypted or similar. Anyone can give me a help? Thank in advance
0
1330
by: VBTricks.de.vu Webmaster | last post by:
Hello, I'm trying to implement an encrypted communication with a PHP script. All the basic stuff (HTTP protocoll, base64) is working. The only problem is that this method works only for the first 8 letters of the encrypted string, the rest seems to be not decrypted. I guess, it's the IV-vector. Unfortunately, I have no experience with encryption:
5
6776
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
2
7693
by: Bernard Dhooghe | last post by:
The information center writes: "Encryption Algorithm: The internal encryption algorithm used is RC2 block cipher with padding, the 128-bit secret key is derived from the password using a MD2 message digest. " and also explains how the length of the encrypted column can be derived.
1
4836
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words, I must be missing out on something crucial. I encrypt a byte array in C# and send over the byte...
2
17968
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of algorithm, initialization vector (IV), mode, padding, key etc, but I just don't get the two languages to "understand each other", or, in other words, I must be missing out on something crucial. I encrypt a byte array in C# and send over the byte...
0
1241
by: ariki | last post by:
Hi all, I am working on the php program to decrypted the password which is encrypted by C#. However, the codes show below could not work. Any ideas? C# coding: private static String password = @"abc"; private static String saltV = @"123"; private static String hashAlgorithm = "SHA1"; private static int passwordIterations = 2; private static String iv = @"123456789123456";
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.