First of all let me point out that I am aware of all the theory behind asymmetric encryption and signing, and other related areas like signcryption, etc. It seems that mathematically it is possible to do what title suggests, however there is not a single working example of how to do it in practice, if possible at all.

I want to ENCRYPT the message/data with a private RSA key (signing it won't suffice) and save it to a file. An application will open that file and decrypt the message with a public RSA key. To point out, anyone can have the public key. This is not a concern in this case.

I want to make it impossible to SEE the message content that is not created by the holder of private key. Signing the message with RSA private key is not acceptable (or signing with a symmetric key and then encrypting the key) because the message content is READABLE but only a subject to validation. Circumventing the authentication validation could be as trivial as a single call patching.

Is there a single working example (that is potentially not ruining the algorithm) of encrypting the message with a private and decrypting the message with a public key. As a side note: it would be great if this would be doable in dotnet.

Thank you very much in advance.

  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – e-sushi
    May 20, 2017 at 1:29

1 Answer 1


OK, so...

The solution I have found, which satisfies exactly what I've been searching for, is based on OpenSSL. I have initially discovered and tested it through the PHP function openssl_private_encrypt (and equivalent openssl_public_decrypt). Since my goal was to implement this in .net project I'm working on, I have ended up with OpenSSL.Net wrapper for C# and a function PrivateEncrypt (and equivalent PublicDecrypt).

For my particular needs, a message, never bigger than a couple of KBs, is split in chunks of 245 bytes (maximum number of bytes encryptable by the private 2048-bit RSA key with PKCS1 padding) and then encrypted with a private key.

On the client side the message is reformed in a reverse process but with public key.

I would like to thank everybody on their contribution and wish to help.


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