0

I can generate, encrypt/decrypt strings by referring to many samples posted in the last decade.

What I really need to accomplish is to be able to:

  1. import private key from a "xxxx.key" key file and encrypt a string with the private key.
  2. And then, extract the public key from a "xxxx.crt" certificate file and decrypt the cypher text.

I have generated public/private keys as well as self-signed certificate and stored in files using openssl binaries.

There are zillion samples that show how to generate keys (not importing from a file) and encrypt via public key.

There is a similar question that was partially answered and is not complete in this thread: How to encrypt a string with private key and decrypt with public key?

I'll appreciate any support and sample code (preferably in C++/C#/VB.NET).

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
DJT
  • 1
  • If you can understand German a little bit (or use Google Translate), I've written [a small article with code snippets on my website](https://entwicklergate.de/t/eine-datei-mit-einem-oeffentlichen-schluessel-zertifikat-verschluesseln-und-mit-einem-privaten-schluessel-zertifikat-entschluesseln/468?u=uwekeim) that does encrypt and decrypt files. Should be very easily adaptable for in-memory strings. – Uwe Keim Jun 17 '21 at 14:39
  • 1
    Ich verstehe ein bisschen Deutsch. Vielen Dank. – DJT Jun 17 '21 at 14:53
  • 1
    Thank you @Uwe Keim. Your arcticle was usefull but still need help. You encrypt file not a string and also use public key for encryption. I need to encrypt a string using a private key. – DJT Jun 18 '21 at 09:50
  • To my knowledge, when doing [asymetic encryption](https://en.wikipedia.org/wiki/Public-key_cryptography), the encryption is _always_ done with the public key and the decryption is _always_ done with the private key. Everything else seems to be of no sense to me. – Uwe Keim Jun 18 '21 at 10:02
  • I understand the conflict. Here is the scenario: I distribute a public key to many. I create a cyphertext with my private key and send. All can decrypt my message via the public key I sent earlier. Theoratically, asymetric keys is the best fit for this job. The problem is I cannot load a private key from file, construct the RSACryptoProvider with the private key and do encryption. – DJT Jun 18 '21 at 10:49

0 Answers0