How to store a private RSA key for an application?

Expect it to be compromised. There isn't a good way to do anything other than obfuscate a private key. The best bet is probably to store it in the cryptographic library of the system that the software is running on. If you're lucky it might have a TPM or HSM that can store the key securely. What are you trying to accomplish with the private key? That might help give better feedback on the best way to securely accomplish your goal.


There is no 100% reliable way to hide a secret of any type, be it a RSA private key or any other kind of object, within an application in such a way that it would resist reverse engineering. All those who have tried, have failed. There are good theoretical reasons why it should not be possible: namely, at some point, the CPU will use the secret value and thus have it under its fingers; by running the code in an emulator, attackers can obtain it as well.

(The emulator is the just-drop-a-nuke-on-it kind of solution; it works and is sufficient to demonstrate impossibility of protection, but attackers invariably use a bit more brain in their reverse engineering.)

The best you can have is user-specific secrets, so that, at least, you can manage things server side by shutting down access for offenders (if an access-granting key is compromised, simply inform the server that this specific key shall no longer be accepted). This is what is done in satellite TV: the signal is broadcasted, with encryption with a key K (which changes every few minutes), and the key K is itself encrypted with the secret key which is in the receiver smart card; each receiver has its own smart card. When a card appears to be massively cloned (breaking a card is expensive, but once it is broken, making 3000 copies is cheap), the TV distributor just stops to distribute the version of K encrypted with the key which is in the compromised card, thus effectively blocking access for all copies.