473,387 Members | 1,757 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,387 software developers and data experts.

RSACryptoServiceProvider DCOM access problem?

Hi all!
I've got really strange (for me) problem:
I've got an application, that at startup decrypts some data. Everything
works fine - the rijndael key is decrypted using the
RSAPKCS1KeyExchangeDeformatter, and the deformatter is created basing on the
RSACryptoServiceProvider and on the RSA key pair stored in the machine key
store. But there is a problem - the application is a COM server, and when I
set it up using DCOMCNFG to be run by a particular user created at
installation, the rijndael key cannot be decrypted - the message is "bad
key". This happens only on the NT machine, W2k works fine... Any
suggestions?
I don't think this is a problem of permissions - the user that runs the
application is in the administrators group.
Maybe it is a problem, that the decryption is done using a COM object
written using C# (with ComVisible=true attribute) and called as a COM
library? Don't know why.
Here is the code:

CspParameters cspParams = new CspParameters(1);
cspParams.KeyContainerName = "mycontainername";
cspParams.KeyNumber = 1;
cspParams.ProviderName = "Microsoft Base Cryptographic Provider v1.0";
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider clientRSA;
try
{
clientRSA = new RSACryptoServiceProvider( cspParams );
clientRSA.PersistKeyInCsp = true;
}
catch( Exception ex )
{
System.Diagnostics.Debug.WriteLine( ex.Message );
return null;
}

RSAPKCS1KeyExchangeDeformatter pRSADef = new
RSAPKCS1KeyExchangeDeformatter( clientRSA );
RijndaelManaged rijndael = new RijndaelManaged();
try
{
rijndael.Key = pRSADef.DecryptKeyExchange( m_byteEncryptedRijndaelKey );
}
catch( Exception ex )
{
//here is the error!
System.Diagnostics.Debug.WriteLine( ex.Message );
return null;
}

I think the problem is with retrieving the key from the machine key store -
some debug logs i've made showed that the RSACryptoServiceProvider is not
initialized properly, but no exception is thrown then. As I mentioned - the
problem occurs only when the running user is different that the logged user
and only on the NT machine.

If you could give me any help...
TIA

--
mYsZa

Jul 21 '05 #1
1 2734
Hi,
If I remember it correctly - on windows prior to W2K, RSA key containers
were stored in HKEY_USER part of registry, but on W2K and later they are
stored in File System %Documents and Settings%\%UserName%\Application
Data\Microsoft\Crypto\RSA\%SID%\. DCOM uses logon as batch job type logon
which doesn't load registry hive - therefore you don't have access to
HKEY_USER registry part and key containers stored there on NT, but keys
stored in file system is readily available for you on W2K and later.

-Valery.

http://www.harper.no/valery

"mYsZa" <el*************@NIEPOTRZEBNEwp.pl> wrote in message
news:c5*********@atlantis.news.tpi.pl...
Hi all!
I've got really strange (for me) problem:
I've got an application, that at startup decrypts some data. Everything
works fine - the rijndael key is decrypted using the
RSAPKCS1KeyExchangeDeformatter, and the deformatter is created basing on
the
RSACryptoServiceProvider and on the RSA key pair stored in the machine key
store. But there is a problem - the application is a COM server, and when
I
set it up using DCOMCNFG to be run by a particular user created at
installation, the rijndael key cannot be decrypted - the message is "bad
key". This happens only on the NT machine, W2k works fine... Any
suggestions?
I don't think this is a problem of permissions - the user that runs the
application is in the administrators group.
Maybe it is a problem, that the decryption is done using a COM object
written using C# (with ComVisible=true attribute) and called as a COM
library? Don't know why.
Here is the code:

CspParameters cspParams = new CspParameters(1);
cspParams.KeyContainerName = "mycontainername";
cspParams.KeyNumber = 1;
cspParams.ProviderName = "Microsoft Base Cryptographic Provider v1.0";
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider clientRSA;
try
{
clientRSA = new RSACryptoServiceProvider( cspParams );
clientRSA.PersistKeyInCsp = true;
}
catch( Exception ex )
{
System.Diagnostics.Debug.WriteLine( ex.Message );
return null;
}

RSAPKCS1KeyExchangeDeformatter pRSADef = new
RSAPKCS1KeyExchangeDeformatter( clientRSA );
RijndaelManaged rijndael = new RijndaelManaged();
try
{
rijndael.Key = pRSADef.DecryptKeyExchange( m_byteEncryptedRijndaelKey );
}
catch( Exception ex )
{
//here is the error!
System.Diagnostics.Debug.WriteLine( ex.Message );
return null;
}

I think the problem is with retrieving the key from the machine key
store -
some debug logs i've made showed that the RSACryptoServiceProvider is not
initialized properly, but no exception is thrown then. As I mentioned -
the
problem occurs only when the running user is different that the logged
user
and only on the NT machine.

If you could give me any help...
TIA

--
mYsZa

Jul 21 '05 #2

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

Similar topics

0
by: Achim Domma (Procoders) | last post by:
Hi, I have a problem with a DCOM server written in python. Here is my minimal test object: class TestObject: _reg_clsid_ = "{ECDBB3BC-F0BF-4eef-87C0-D179A928DAB5}" _reg_progid_ =...
4
by: mYsZa | last post by:
Hi all! I've got really strange (for me) problem: I've got an application, that at startup decrypts some data. Everything works fine - the rijndael key is decrypted using the...
2
by: David Olive | last post by:
Hi guys, I'm having a bit of a problem getting a VB .NET console app to run happily as a scheduled task. The app itself generates a bunch of word documents on a file share on another server by...
1
by: DotNetJunkies User | last post by:
Hi, I have a web application that accesses a DCOM. Every thing works fine on Windows XP sp1 but when I installed service pack 2 I got an access denied when the application tried to create an...
2
by: c.verma | last post by:
I have a web based (forms based authentication) asp.net application that uses .NET remoting. It has web.config.remoting with all the required settings in it. As soon as it tries to access the...
0
by: khubieb | last post by:
Simply I am trying to use RSACryptoServiceProvider to generate a key pair, send the public key to a service that will retrieve me data, encrypt it with my public key, send the encrypted data back...
0
by: Ismail Fatih Yıldırım | last post by:
I modified the RSACSPSample from MSDN to try out a simple commutative encryption model using RSA encryption but when i run the progrem the first encryption command works but during the second...
2
by: =?Utf-8?B?R2FicmllbCBNw6luZGV6?= | last post by:
Hello everyone. I have a small class that encapsulates some functionallity to work with the RSACryptoServiceProvider. Here is the code of the class i'm using: public class dsRSA { private...
0
by: Olli Goessler | last post by:
Hi Guys, (sorry for my bad english) i have a question for the following problem: With the RSACryptoServiceProvider object... Application A: // Generate a public/private key pair....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.