2

How can I use private/public keys for encryption/decryption of an an excel file in C#.NET?

The article RSA Encryption in C# describes a way of doing this encryption, but this example only works for encrypting/decrypting text, not for an excel file.

How can I encrypt / decrypt an excel file (using asymmetric RSA encryption)?

poupou
  • 43,413
  • 6
  • 77
  • 174
RedsDevils
  • 1,413
  • 9
  • 26
  • 47

2 Answers2

2

The link you provide is not the way you should use RSA to encrypt data (such as a file). I have an old (but still up to date) blog entry on the subject:

http://pages.infinit.net/ctech/20031101-0151.html

poupou
  • 43,413
  • 6
  • 77
  • 174
  • 1
    Could you add the essence from your blog article ("combine RSA with a symmetric encryption") to your answer? This way it stays useful even if your blog dissappears. – Paŭlo Ebermann Aug 12 '11 at 18:50
  • That page was made in 2003 (way before stackoverflow ;-) because I could not bear to repeat its content everytime the question was asked (mostly in newsgroup at the time). It's well linked-in and archived at http://web.archive.org/web/20031204135734/http://pages.infinit.net/ctech/20031101-0151.html – poupou Aug 14 '11 at 16:51
0

One way...

In the EncryptData method of that article it accepts a string to be encrypted which it then converts to bytes before encrypting it. To get the bytes from a file, you can use a FileStream.

Simply change the method so that the parameter is a filepath instead of text data, and use the filestream to Read/Write bytes as required. Likewise for the DecryptData method.

Smudge202
  • 4,689
  • 2
  • 26
  • 44