468,738 Members | 2,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

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 2187
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Bailey | last post: by
1 post views Thread by Jase H | last post: by
3 posts views Thread by =?Utf-8?B?TG9yZW4=?= | last post: by
9 posts views Thread by Betikci Boris | last post: by
9 posts views Thread by Alan M Dunsmuir | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.