2

First let me start by saying I'm sorry if I posted this question in the wrong place. I saw the entry at Object already exists in RSACryptoServiceProvider. I tried the solutions offered there. But, they did not solve my issue. Also, I didn't see an option to re-ask the question.

I have almost the same issue. I have a class that uses RSACryptoServiceProvider that runs in two projects on the same machine and under the same account. Both projects live in the same solution and share the same encryption code. One project, the server, is a Windows service and the other, the client, is a Windows application. They use the RSACryptoServiceProvider to talk to each other over a named pipe using asymmetric encryption. I started out by just having the server run in another Windows form within the same application as the client. Everything ran fine. Then, I moved the server to a Windows service.

The Windows service starts up fine. It seems to be able to create it's instance of the RSACryptoServiceProvider fine. But, when the client, which runs in the Windows application, starts up it gets a runtime error when it tries to create it. Here is the code that runs in both projects.

rule = New CryptoKeyAccessRule("everyone", CryptoKeyRights.FullControl, AccessControlType.Allow)
csp = New CspParameters
csp.KeyContainerName = _KeyContainerName
csp.Flags = CspProviderFlags.UseMachineKeyStore
csp.CryptoKeySecurity = New CryptoKeySecurity()
csp.CryptoKeySecurity.SetAccessRule(rule)

//Object already exists exception happens here
rsa = New RSACryptoServiceProvider(_KeySize, csp)

As you can see, I have the code that sets the access rule as mentioned in the other post on this subject. Unfortunately, this did not solve my issue. Is there anything else that needs to change?

Community
  • 1
  • 1
Mikutus
  • 83
  • 1
  • 10
  • You say you run into almost the same issue. What's different from the other post that would warrant a new question? – Maarten Bodewes Jul 25 '12 at 17:50
  • In the other post, setting the access rule resolved the issue. It appears that I am running into a different issue because that did not resolve it. – Mikutus Jul 25 '12 at 18:00
  • I think I found the solution to this issue. I just changed the code so that each application uses a different KeyContainerName. I changed the line to this. csp.KeyContainerName = _KeyContainerName & "." & My.Application.Info.Title Are thier any issues that this could cause? – Mikutus Jul 25 '12 at 18:00
  • As for the other question, as nothing was accepted, we don't know if it solved the issue. Your issue certainly seems different, and if you post it as an answer I will certainly vote for it. Separate key container (names) certainly seems a good idea to me, but personally I have no experience with it. – Maarten Bodewes Jul 25 '12 at 21:54

0 Answers0