-1

I'm using C# Chilkat library. In this example; I can encrypt the file with public key and open it with private key. But in my scenario there is no physical file for encrypt, at runtime I have byte arrays. And I want to encrypt it with public key and save as a file. Then I want to decrypt it with private key. Is there anyway to do it? I can't find any sample code about this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
andy kary
  • 39
  • 4

1 Answers1

0

It is possible to do that. If you looked over the whole example closely, you will have seen this line:

string encryptedAesKey = rsa2.EncryptStringENC(randomKey,bUsePrivateKey);

Earlier in the program, I saw that randomKey is a string. So that is how you can encrypt strings in memory. The program does not show how to encrypt a byte array, but clicking on the Chillkat.Rsa hyperlink in the program, you will go to this page.

There, you will see the methods available to you. EncryptStringENC is there, the method to encrypt a string and return a string. Note that there are 3 other Encrypt methods there, 2 of which will accept a byte array, one returning an encrypted string and the other an encrypted byte array. You should choose the one among these that meets your requirements.

As for saving the encrypted byte array to file, there are a lot of tutorials on saving to file, so for sake of brevity, I will not go into that here.

WDS
  • 966
  • 1
  • 9
  • 17