At the moment I am looking into the most secure way to store a private RSA key on Windows.

Making it as much usable for the end user as possible, while keeping the security to its highest. As this is practically impossible I am not sure where to exactly go with a compromise. Maybe I am forgetting about another possibility and would like to ask for help from the information security board.

Scenario: A user generates an RSA key pair. This is frequently used to encrypt/decrypt AES keys to then access actual data. Lets say its a chat application, or an application like dropbox for files. The purpose doesn't really matter as the focus lies on the way the RSA private key is stored and can be accessed.

The workflow of the user: Login Windows -> Start App -> Login via API to webserver -> successful login -> access private key locally -> perform task x (chat, file, etc...)

The possibilities:

  1. SQLite Database where the private key is unencrypted in PEM format. The DB is "encrypted" and the password is saved in the .net application as a string Quick and dirty. I'd say bad practice. However, other applications cannot access the SQLite database as they do not know the key.

  2. CryptoAPI .NET using the RSA User Key Container. While having DenyExport and other flags on, any app can access the key while the user is logged in. With mimikatz and similar software it's quite easy to export the private key even though it is not exportable.

  3. .NET DAPI is not really for protecting RSA Keypair and more interesting for sensitive information in memory. No point at all

  4. Simply export the PEM key as password protected key. Usability goes down as the user would need a 2nd password to access the key.

  5. Isolated Data .NET - out of question.

Is there another way to store a private key in a secure but practical manner on a windows system ?

2 Answers 2


If your app running as the user can access a chunk of data, any process running as that user can access it too. As you saw in your investigation of option 2, determined programs will be able to find the data if it's stored without additional encryption. If you implement some encryption, as in option 1, somebody could reverse engineer your application to figure out how the encryption works, and then their app - if run as that user - can get at the key.

The only way to stop a program running as your user from accessing the keypair is to not let your program be able to decrypt it alone. That is, you should either store the key offline (like on a flash drive that the user plugs in when needed) or encrypt it with a password that the user types in each time (i.e. the password is never stored). That way, even if another program steals the protected data, it can't get the key.

Either way though, a sophisticated attacker would create a program that waits for the key to be loaded into memory and then steals it. In Windows, applications aren't security principals. If the user can get at data, applications running as that user can get it too.


The most secure way to store a private key is to generate it on a smart card or in an HSM. Is that an option?

The smart card or HSM can still be used to encrypt and decrypt by whoever has access, but it won't give up the key.

You can put the public key wherever you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .