How to do asymmetric encryption with X509 certificates and C#?

c#, encryption, x509

Solution

See this SO question how to create a `RSACryptoServiceProvider` from a `X509Certificate2` that can be used to encrypt and decrypt files.

The .NET framework does not contain classes to generate X.509 certificates. Mono's security classes (`Mono.Security.X509`) and BouncyCastle support the creation of X.509 certificates from C#. Alternatively, you can use tools like OpenSSL or `makecert.exe` to generate certificates.

Problem

I am looking to encrypt files with X509 certificates using public and private keys and send them to a remote server. How would I do this? Is this even possible? How do I generate the certificate and then the public and private key pairs?

Original source

Related problems