1

Looking for a bit of advice really, here's the situation:

  • I currently have a security minded client who will be sending PGP encrypted files.

  • I have to decrypt the files on my server before processing them. To achieve this I was thinking of using BouncyCastle with C#.

Ok, so far so good... but... I was wondering what the best method of storing my private key on my server would be?

  • I know that the thought of simply storing my private key in a file (even though it'll have a pass-phrase) in a restricted folder will be enough to make my client's left arm go numb!

  • The simplest option I can think of would be to use BouncyCastle's keystore, however I'm not sure which the most secure option: Keystore.BouncyCastle, Keystore.UBER or The PKCS12 compatible keystore. Either way I'd have to justify the decision (it's still just a file in a folder :( !!), does anyone know of some relevant reading?

  • I'm not sure if it would be possible to use Windows CNG to store the keys instead of BouncyCastle's keystore?

  • Is there another, better option?

Ooo, just a little note: I'm not 100% attached to BouncyCastle if there's a better option out there I'd be more than happy to use that (esp. if it doesn't involve handing over fist-fulls of cash & I can automate it)

1

Generally speaking, it all depends on what you need to protect against and in what context: you need to explain first what you want to protect against and then design a sensible strategy for this: protecting against remote access is not the same as protecting against someone having access to the hardware. The running environment is important as well: you can't use a HSC the same way on a dedicated server located in your server room and on a VM rented from a public cloud.

Now, to be more specific: in case of server application, encryption is usually done in a way that will make it hard form someone who gained read addess to the data and source code of the application. This suppose that the operating system itself remains (more or less) secure and that the intruder doesn't get access to your running process (otherwise, he might as well just read the cleartext from memory).

For that, Windows offers a convenient way to protect data through the CryptProtectData and CryptUnprotectData APIs. These functions will allow you encrypt an arbitrary block of data using a key that is tied either to the logged on user account or to the local machine (you can add and additional key if you desire so although you will need to be able to store that externally somehow: it's of limited use if you have no secure storage available).

Doing the above is very easy and straightforward: that is basically how most of Windows stores secret data. Unfortunately, it has one major limitations: is of no use against any code that can run in the same context as your program. This means that it will be of no use in case of access to the physical machine or in case of any type of code injection flaw. Nevertheless, if you keep that in mind and if you deem that limitation acceptable, you can use these API to store the passphrases for your private 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.