September 2003
Intermediate to advanced
624 pages
14h 27m
English
You need to securely send a DataSet
over
a connection that is not secure.
Encrypt and
decrypt
the DataSet using the .NET cryptographic services,
and serialize and save the encrypted DataSet to a
stream (such as a file or network stream).
The sample code contains two event handlers:
Button.ClickThe first Button.Click creates a
DataSet and encrypts it using the algorithm
specified by the user and writes the encrypted
DataSet to a file.
Button.ClickThe second Button.Click decrypts a file containing
a DataSet previously encrypted using an algorithm
specified by the user and uses the file to recreate the
DataSet previously encrypted.
The C# code is shown in Example 5-7.
Example 5-7. File: SecureTransmissionForm.cs
// Namespaces, variables, and constants using System; using System.Configuration; using System.Windows.Forms; using System.Xml; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Security.Cryptography; using System.Data; using System.Data.SqlClient; // Table name constants private const String ORDERS_TABLE = "Orders"; private const String ORDERDETAILS_TABLE = "OrderDetails"; // Relation name constants private const String ORDERS_ORDERDETAILS_RELATION = "Orders_OrderDetails_Relation"; // Field name constants private const String ORDERID_FIELD = "OrderID"; private RSACryptoServiceProvider rSAReceiver; private const int keySize = 128; // DES key ...
Read now
Unlock full access