473,224 Members | 1,362 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,224 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 2430
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.