I have a Service written in c# which uses asymmetric Encryption to Encrypt Data, and a client application which Decrypts the Encrypted data received from the service.

How can I do the following things ?

  1. I need to save the private key in a secure way that no one can read it (preferably in DB).
  2. Transfer the public key securely to the client application.
  3. How can I make sure the key can only be used by the Client Application not any other applications
  • 4
    The public key doesn't have to be securely transferred since by nature it's supposed to be exposed to the public. For secure key management, I'd recommend checking out NIST standards, csrc.nist.gov/groups/ST/toolkit/key_management.html – RoraΖ Sep 11 '14 at 14:41
  • I'd modify your title to ask the most important of the 3 questions. As @raz says, there is no need to transfer public keys securely. – schroeder Sep 11 '14 at 18:14

1: There are a variety questions and answers here on how to secure a Private Key for an app/database.

2: No need to securely transfer a Public Key. What I'm assuming you're looking for is a secure means to transmit a shared secret (see next)

3: To ensure that only two particular nodes can see a communication, you need some kind of double encryption. You typically use a shared secret to encrypt a message then re-encrypt with the sender's private key. This is the basics of how an encrypted tunnel is created. That way, only those with the shared secret can ultimately read the message. Read up on the basics of HTTPS and VPN setup for tips.


For #1 the usual answer would be to the store the key in an HSM (hardware security module). This is the only truly secure way to store a private key, as any keys simply stored on the hard drive will be compromised if your machine is compromised.

Question #2 is what is usually solved by a PKI (public key infrastructure). Others have said that there is no need to securely transfer a public key, but this is not entirely true; if someone were to perform a man-in-the-middle attack and insert their public key instead, then they would be able to decrypt all future communication. The key itself is not sensitive, and doesn't need to be secured, but you do need some way of ensuring that it is authentic. Confidentiality is not required but authenticity is.

When you use a PKI, the public key is signed by another key higher up the hierarchy to produce a certificate, and this signature verifies that the key is authentic. Of course, then you have the issue of distributing the public key of the next key up the hierarchy and so on. Generally this is solved by distributing the root public key along with your application, as a trusted root CA (certificate authority), then this can be used to verify the authenticity of any certificate chains with this CA at their root.

Question #3 is again something that can be achieved if you are using an HSM to secure your keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.