views:

147

answers:

2

I have the following situation:

Several applications in different machines are going to share a information stored in a database with RSA cryptography.

Today I'm doing this in a way it's not the safer way. These machines share a DLL containing the RSA key in a XML.

How could I use the information from this XML to generate machine keys in the different machines and after that, how could I use them in RSACryptoServiceProvider?

+2  A: 

What I have done in the past: (This is just an outline; if you need actual code, I could provide it, but it sounds like your question is just looking for ideas.)

The following must be done on each machine. (You can create a simple console app to do this, or a powershell script.)

  • Use ProtectedData.Protect to encrypt the key
  • Store the encrypted key in the registry. You can set the ACL permissions on the registry key for additional security.

In your app, use ProtectedData.Unprotect to get the key, then pass that to the RSACryptoServiceProvider for encrypting and decrypting.

Dave
Hi Dave, my problem is really how could I do it, I don't know a code or a tool that can generate a machine key from a xml or something. I need to keep this "master key" to generate this machine key to other machines.
Victor Rodrigues
The ProtectedData class takes care of this for you. It uses DPAPI (built into Windows) to generate a machine-specific (or user-specific) key for encryption. That key is different on each machine, however, which is why you have to run the `.Protect` / registry on each machine. Once that is done you can delete in XML file. (Store the actual RSA key in KeePass or something so you can refer to it later if you need it.) This way there is absolutely no "plain-text" key anywhere, and your security is based on Windows-standards (account permissions / ACL)
Dave
Sorry, I'm not going to be able to get to this right now. But http://blog.shutupandcode.net/?p=538 has the first part; I would only add the ProtectedData stuff above on the private key XML so that your private key cannot be easily compromised.
Dave
A: 

Constructor of RSACryptoServiceProvider() can be used to create new key pair. If you want to create a Machine key or define some other parameters of created key pair you should use RSACryptoServiceProvider(CspParameters parameters) constructor. So create a new CspParameters instance, for example cspParams, and fill cspParams.Flags to CspProviderFlags.UseMachineKeyStore. Then you will be able with respect of RSACryptoServiceProvider(CspParameters parameters) constructor create a machine key.

Oleg