473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ConnectionString encryption decryption

Hello,

I have a ASP.NET web application problem involving the data encryption and
decryption assembly(DLL) used on the connection string value that is set in
the webconfig file.
The problem occurs in the application when you instantiate a new instance of
the class as shown below:

---Dim dp As DPAPIComp.DataProtectorComp = New DPAPIComp.DataProtectorComp---
where DPAPIComp is the name of the namespace referenced to in the library
and DataProtectorComp is the class. This class contains the Encrypt and
Decrypt function used to encrypt and decrypt the connection string pass to
it.

Below is the code responsing to the call above. (in the form of an assembly)

using System;
using System.EnterpriseServices;
using System.Security.Principal;
using System.Runtime.InteropServices;
using DataProtection;

namespace DPAPIComp
{
public class DataProtectorComp: ServicedComponent
{
public byte[] Encrypt(byte[] plainText)
{
DataProtector dp = new DataProtector( DataProtector.Store.USE_USER_STORE );
byte[] cipherText = null;
try
{
cipherText = dp.Encrypt(plainText, null);
}
catch(Exception ex)
{
throw new Exception("Exception encrypting. " + ex.Message);
}
return cipherText;

}
public byte[] Decrypt(byte[] cipherText)
{
DataProtector dp = new DataProtector( DataProtector.Store.USE_USER_STORE );
byte[] plainText = null;

try
{
plainText = dp.Decrypt(cipherText,null);
}
catch(Exception ex)
{
throw new Exception("Exception decrypting. " + ex.Message);
}
return plainText;
}

public DataProtectorComp()
{

}
}
}
--------------------------------------------

The error message as it passes this line in the debugger is "Access is
denied".
Source: "mscorlib"
StackTrace: " at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode,
IntPtr errorInfo)
at System.EnterpriseServices.Thunk.Proxy.CoCreateObje ct(Type serverType,
Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri)
at
System.EnterpriseServices.ServicedComponentProxyAt tribute.CreateInstance(Type
serverType)
at
System.Runtime.Remoting.Activation.ActivationServi ces.IsCurrentContextOK(Type
serverType, Object[] props, Boolean bNewObj)
at BoardroomBookings.DBConnection.GetConnectionString (String Name,
String& CnnStr) in C:\Inetpub\wwwroot\BoardroomBookings\DBConnection. vb:line
14" String

--------------------------------------------
I have tried placing the DLL in the GAC and giving it a strong name and that
still give the same error message. The DPAPI solution was built successfully.
Would this indicate that there is some sort of permission being applied to
the encryption/decryption call because I cannot connect to the server.
How do I get it to instantiate this probably and be able to connect to the
database.

Cheers,

Please note the same version works on the server but does not work on my
local workstation. Does this tell you something?
Jul 21 '05 #1
1 2442
the stack trace suggests that you are going through COM interop and the fact
that you have derived from ServicedComponent also suggests that you are
running in COM+.

I can't see any reason why you would want to do that since there is no
reason for this code to be using any COM+ services - but that's obviously a
seperate discussion.

At a guess it looks like you have some security applied to the COM+ package
which is causing the 'access denied'. Although you'd have to supply more info
about the how all the bits are configured.

Regards
Niroo T [MSFT]

"Jase H" wrote:
Hello,

I have a ASP.NET web application problem involving the data encryption and
decryption assembly(DLL) used on the connection string value that is set in
the webconfig file.
The problem occurs in the application when you instantiate a new instance of
the class as shown below:

---Dim dp As DPAPIComp.DataProtectorComp = New DPAPIComp.DataProtectorComp---
where DPAPIComp is the name of the namespace referenced to in the library
and DataProtectorComp is the class. This class contains the Encrypt and
Decrypt function used to encrypt and decrypt the connection string pass to
it.

Below is the code responsing to the call above. (in the form of an assembly)

using System;
using System.EnterpriseServices;
using System.Security.Principal;
using System.Runtime.InteropServices;
using DataProtection;

namespace DPAPIComp
{
public class DataProtectorComp: ServicedComponent
{
public byte[] Encrypt(byte[] plainText)
{
DataProtector dp = new DataProtector( DataProtector.Store.USE_USER_STORE );
byte[] cipherText = null;
try
{
cipherText = dp.Encrypt(plainText, null);
}
catch(Exception ex)
{
throw new Exception("Exception encrypting. " + ex.Message);
}
return cipherText;

}
public byte[] Decrypt(byte[] cipherText)
{
DataProtector dp = new DataProtector( DataProtector.Store.USE_USER_STORE );
byte[] plainText = null;

try
{
plainText = dp.Decrypt(cipherText,null);
}
catch(Exception ex)
{
throw new Exception("Exception decrypting. " + ex.Message);
}
return plainText;
}

public DataProtectorComp()
{

}
}
}
--------------------------------------------

The error message as it passes this line in the debugger is "Access is
denied".
Source: "mscorlib"
StackTrace: " at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHR(Int32 errorCode,
IntPtr errorInfo)
at System.EnterpriseServices.Thunk.Proxy.CoCreateObje ct(Type serverType,
Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri)
at
System.EnterpriseServices.ServicedComponentProxyAt tribute.CreateInstance(Type
serverType)
at
System.Runtime.Remoting.Activation.ActivationServi ces.IsCurrentContextOK(Type
serverType, Object[] props, Boolean bNewObj)
at BoardroomBookings.DBConnection.GetConnectionString (String Name,
String& CnnStr) in C:\Inetpub\wwwroot\BoardroomBookings\DBConnection. vb:line
14" String

--------------------------------------------
I have tried placing the DLL in the GAC and giving it a strong name and that
still give the same error message. The DPAPI solution was built successfully.
Would this indicate that there is some sort of permission being applied to
the encryption/decryption call because I cannot connect to the server.
How do I get it to instantiate this probably and be able to connect to the
database.

Cheers,

Please note the same version works on the server but does not work on my
local workstation. Does this tell you something?

Jul 21 '05 #2

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

Similar topics

2
by: Dave Bailey | last post by:
I have developed a web app using DPAPI to encrypt a connection string in the web.config file. The application works perfectly on the development machine but when deployed to the server when...
1
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem...
2
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the...
3
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do:...
4
by: Fritjolf | last post by:
Hi. I've got a strange problem... I've made a simple program to test encryption/decryption. I use Rijndael encryption and here are the most important properties. RijndaelManaged cipher =...
3
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the TripleDESCryptoServiceProvider encryption found in System.Security.Cryptography. Below is the code for my Encrypt and Decrypt...
5
by: Netwatcher | last post by:
well, i started messing around with dictionaries, yet, most of the pages i found about them always talk about getting only one word out of it and turning it vice versa, i've been playing with that...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
9
by: Alan M Dunsmuir | last post by:
In my (PHP-5) application I have to write some records to a table in my database, which I don't want even my clients using the system to be able to read. This is not a problem in National...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.