I have a simple encryption application where I will be encrypting "sensitive" data in a database. Only the people who have access rights can see these data in decrypted form. I have been looking around for more information on how to do that and here is my project approach:
- I am using AES encryption algorithm.
- Generate an AES key with RNGCryptoServiceProvider. Encrypt info with AES key.
- Encrypt the AES key with and RSA public key.
- Store the private key in a USB file, which I will only give to the people who can have the access rights.
- When a rightful person needs to see the decrypted information, they will provide the private key. The app uses the private key to decrypt the AES key, which in turns decrypts the information.
Now, my question is how can I safely store that private key? From what I have been reading, I can obtain the private key using FromXMLString. But, I was thinking that if someone somehow gets the USB file and the XMLFile, he can find the private key by using the FromXMLString similarly. So, how can I protect that file, for example, by using a passphrase? Is there any function in c# i can use for that?
Also, if I change the key pairs, I have to change the public key and re-encrypt the AES key again with the fresh new public key. For that, I found this post How to Generate Unique Public and Private Key via RSA to be quite useful. But, something I am not sure about how the author implemented it. Does he also store the key container name in the private key file? Or the ToXMLString automatically does that?
Thanks~