swiftgp
swiftgp

Reputation: 1015

Encrypt XML file out of a Dataset

I have a winforms application that connects to a couple of databases. However, I would like my app to be used even when the user is not connected to the internet. I had been writing datasets to XML files locally and reading them in based on the user preference whether to download from the database or use a local data file.

DataSet.WriteXml(localPath)

As the application is improving, I would like to encrypt the XML file to prevent the user from looking inside (There is a bunch of data in there but the application selectively displays data based on access levels assigned to users). I looked into 'Rijndael Managed' and got a prototype working based on Encrypt/Decrypt Files in VB.NET. I have not been able to figure how to pass in a stream to cryptography classes without them ever being saved to the disk.

Right now, I save the xml file out of the Dataset to a temporary directory and construct a new stream and pass it in to CrypotoStream which then writes an encrypted file to the desired location.

I am looking for a solution to directly pass in the stream without ever writing it to the disk. Please suggest.

Upvotes: 1

Views: 1686

Answers (2)

MethodMan
MethodMan

Reputation: 18863

a better thing to use would be the EncryptedXml Class

EncryptedXml Class Encryption can entail different approaches for cryptographic strength, key bases, etc. Follow the examples in the MSDN documentation. This is not a short implementation, but it works extremely well.

other alternatives

Write into a MemoryStream and use MemoryStream.ToArray();

to read the encrypted stream

Just use the CryptoStream to load the DataSet.

refer to this like to read/decrypt Read/decrypt encrypted XML file and then process internally

Upvotes: 2

Volma
Volma

Reputation: 1345

Sounds like MemoryStream may be what you are looking for.

Upvotes: 1

Related Questions