0

I am trying to encrypt the entire xml file for security, including its nodes and values. I have done something but I am not sure if it is correct way to do it. And also I am getting a null exception during the runtime

Encryption scrty = new Encryption("arif");
XmlDocument doc = new XmlDocument();
doc.Load("D:\\PROJELE\\XML\\Language.xml");
string tst = scrty.Encrypt(doc.InnerXml);
doc.InnerText = tst;  // "null exception" is thrown here************
doc.Save("D:\\PROJELER\\XML\\Language2.xml");

After encryption, how can I assign it encrypted text to doc? is there any other way to do this?

Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189
  • Seems like a duplicate of http://stackoverflow.com/questions/14008090/how-would-i-read-and-write-encrypted-xml-files to me – Dave Aug 30 '13 at 11:33
  • no way. my question is not totally about security. it is about the writing back the encrypted text to xml – Arif YILMAZ Aug 30 '13 at 11:35

2 Answers2

0

doc.InnerText = tst;

it means that your call

string tst = scrty.Encrypt(doc.InnerXml);

is returning null. Now show us the working of Encryption.Encrypt so that we can tell you why it is returning null, or diagnose it yourself.

and for encryption you can see MSDN

Ehsan
  • 31,833
  • 6
  • 56
  • 65
0

Either:

  • doc element is null now
  • tst is null
  • or some encoding issues in tst (encrypted text)

Show us the encrypted text, or debug to see if anything is null

Irfan
  • 2,713
  • 3
  • 29
  • 43