Current .Net Version: 2.0.50727
Home
Articles
C# & .Net Framework Reference
Practice C# Online
XML Web Services
RSS Feeds
Code Snippets
T-SQL Scripts
Videos
Valuable Links
Contact Us
Mike's C#, VS.NET and SQL Blog




ROR XML Info.
Visual C# Code Snippets

Click here for information on how to use code snippets in VS.NET (2005+)

Encrypting and Decrypting DataSets [Code | XML]

Title: Encrypting and Decrypting DataSets
Shortcut: encdecdataset
Description: Provides two methods for encrypting and decrypting data from a single instance of a DataSet. Calling EncryptDataSet() will cause three files to be generated: 1) a serialized jagged byte array holding the DES key and vector, 2) the encrypted DataSet instance's data and 3) the DataSet instance's schema. Calling DecryptDataSet() will read the preceding three files: 1) it will deserialize the DES key and vector, 2) decrypt and load into the DataSet instance the data and 3) load into the DataSet instance the schema. Note that these two methods will work with one instance of a DataSet. If you call EncryptDataSet() with several instances, you may encounter problems. Therefore, the preceding methods are designed to deal with one instance of a DataSet. If you require encryption and decryption for several DataSet instances then you should pass the methods unique file names for each one accordingly. Please note that this code is the most basic employed. You should implement try-catch blocks as well as conditional checks for the existence of the various files being read and written to. Also, be aware that if you intend to decrypt the DataSet, you must have present all three of the files discussed above. So, for example, if you plan on encrypting the DataSet on computer A and decrypting it on computer B, make sure the files generated are copied to computer B before decryption occurs (ensuring that the paths to the files are properly set as well).
Author:

Declarations:
Literal:
ID: strDESBinFile
Type: System.String
ToolTip: The file that is to store the serialized jagged array of both the DES' Key and IV byte arrays.
Default: "DES.bin"
Literal:
ID: strDataSetBinFile
Type: System.String
ToolTip: The file that is to store the encrypted DataSet instance.
Default: "DataSet.bin"
Literal:
ID: strDataSetSchemaFile
Type: System.String
ToolTip: The file that is to store the DataSet instance's schema.
Default: "DataSet.xsd"
Code View:

XML View:

Open/Save | E-mail | Back
 
COPYRIGHT/DISCLAIMER | CONTACT US