Click here to Skip to main content
15,907,687 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
Question.NET (specifically C++ .Net) and GUI Development? Pin
SteveTheTechWriter10-Nov-03 5:23
SteveTheTechWriter10-Nov-03 5:23 
AnswerOpinion Pin
E.L. Golpe10-Nov-03 5:55
E.L. Golpe10-Nov-03 5:55 
AnswerRe: .NET (specifically C++ .Net) and GUI Development? Pin
berndg10-Nov-03 21:46
berndg10-Nov-03 21:46 
Questionhow to install a class into .NET Framework? Pin
sacoskun9-Nov-03 6:02
sacoskun9-Nov-03 6:02 
AnswerRe: how to install a class into .NET Framework? Pin
E.L. Golpe10-Nov-03 5:46
E.L. Golpe10-Nov-03 5:46 
GeneralJar Files Too Pin
E.L. Golpe10-Nov-03 5:49
E.L. Golpe10-Nov-03 5:49 
QuestionWinForms DataSet Read Encrypted XML ??? Pin
E.L. Golpe8-Nov-03 8:24
E.L. Golpe8-Nov-03 8:24 
AnswerHeres the code I'm using Pin
E.L. Golpe10-Nov-03 5:23
E.L. Golpe10-Nov-03 5:23 
Heres the code I have thus far. I can get it to encrypt it seems but Im not sure if it is encrypting correctly, or decrypting correctly...

I use the Page_Load just to debug by loading a standard authors.xml file...

I keep getting a root element missing exception when trying to load the encrypted file.

I am using a static key and IV and I know I should use ASCIIEncoding instead of UnicodeEncoding for that but will change it later once I can get it working....

[code]
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace ReadingXML
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnReadXML;
private System.Windows.Forms.Button btnShowSchema;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnUpdateXML;
DataSet dsAuthors = new DataSet("authors");


public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.btnReadXML = new System.Windows.Forms.Button();
this.btnShowSchema = new System.Windows.Forms.Button();
this.btnUpdateXML = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 232);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(672, 104);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(680, 224);
this.dataGrid1.TabIndex = 1;
//
// btnReadXML
//
this.btnReadXML.Location = new System.Drawing.Point(40, 344);
this.btnReadXML.Name = "btnReadXML";
this.btnReadXML.TabIndex = 2;
this.btnReadXML.Text = "Read XML";
this.btnReadXML.Click += new System.EventHandler(this.btnReadXML_Click);
//
// btnShowSchema
//
this.btnShowSchema.Location = new System.Drawing.Point(136, 344);
this.btnShowSchema.Name = "btnShowSchema";
this.btnShowSchema.Size = new System.Drawing.Size(88, 23);
this.btnShowSchema.TabIndex = 3;
this.btnShowSchema.Text = "Show Schema";
this.btnShowSchema.Click += new System.EventHandler(this.btnShowSchema_Click);
//
// btnUpdateXML
//
this.btnUpdateXML.Location = new System.Drawing.Point(248, 344);
this.btnUpdateXML.Name = "btnUpdateXML";
this.btnUpdateXML.TabIndex = 4;
this.btnUpdateXML.Text = "Update XML";
this.btnUpdateXML.Click += new System.EventHandler(this.btnUpdateXML_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(688, 381);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnUpdateXML,
this.btnShowSchema,
this.btnReadXML,
this.dataGrid1,
this.textBox1});
this.Name = "Form1";
this.Text = "ReadingXMLExample";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
// string cryptFile="C:\\Documents and Settings\\Eric L. Golpe\\My Documents\\Visual Studio Projects\\ReadingXML\\bin\\authors.xml";
// DataSet dsAuthors = new DataSet();
// dsAuthors.ReadXml(cryptFile);
// dataGrid1.DataSource = dsAuthors;
// dataGrid1.DataMember = "authors";
// dataGrid1.CaptionText = dataGrid1.DataMember;
}


private void btnReadXML_Click(object sender, System.EventArgs e)
{
try
{

// The encrypted file to be read from.
string cryptFile="C:\\Documents and Settings\\Eric L. Golpe\\My Documents\\Visual Studio Projects\\ReadingXML\\bin\\authors.bsc";

// Create key and IV hash
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes("elg08754");

// Instantiate new crypto object
RijndaelManaged RMCrypto = new RijndaelManaged();

// Create an instance of StreamReader to read from a file.
FileStream cryptedstream = new FileStream(cryptFile, FileMode.Open, FileAccess.Read);

// Create New MemoryStream object to hold unencrypted data
MemoryStream memstream = new MemoryStream();

// Open a CryptoStream linking objects
CryptoStream cs = new CryptoStream(cryptedstream,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);

int data;
while ((data=cs.ReadByte())!=-1)
memstream.WriteByte((byte) data);

// Create the DataSet to hold the data.
DataSet dsAuthors = new DataSet();

// populate the dataset with the XML String now in memstream
dsAuthors.ReadXml(memstream, XmlReadMode.ReadSchema);

// Set the datasource and display the data;
dataGrid1.DataSource = dsAuthors;
dataGrid1.DataMember = "authors";
dataGrid1.CaptionText = dataGrid1.DataMember;

// Close the streams
cs.Close();
memstream.Close();

// We're good, set the 'good to go' message
MessageBox.Show("Everything is OK", "OK");

}
catch (Exception x)
{
MessageBox.Show("Decryption failed!\nSpecific Details: " + x.ToString(), "Error");
}
}

private void btnShowSchema_Click(object sender, System.EventArgs e)
{
System.IO.StringWriter swXML = new System.IO.StringWriter();
dsAuthors.WriteXmlSchema(swXML);
textBox1.Text = swXML.ToString();
}

private void btnUpdateXML_Click(object sender, System.EventArgs e)
{
// The following function uses Rijndael encryption algorithm to encrypt file
// Because the Rijndael algoritm is private-key algoritm we need one
// private key and IV. I composed private key from password entered by user.
// IV is the same as password but this probably is not good.
// A key and IV have to be exactly 16 bytes length so we have to truncate
// password if it is longer then 8 characters (16 bytes) or to add some characters
// if password length is less then 8 characters.

try
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes("elg08754");

string cryptFile="C:\\Documents and Settings\\Eric L. Golpe\\My Documents\\Visual Studio Projects\\ReadingXML\\bin\\authors.bsc";
FileStream fsCrypt=new FileStream(cryptFile, FileMode.OpenOrCreate);

RijndaelManaged RMCrypto = new RijndaelManaged();

//Create a new temporary stream object
MemoryStream memIn=new MemoryStream();

// Write XML formatted data to the crypto stream with the schema from the dataset to the stream
dsAuthors.WriteXml(memIn, XmlWriteMode.IgnoreSchema);

//Creat the CrytoStream Object to do the encryption.
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);

// Write the crypted data to the MemoryStream;
int data;
while ((data=memIn.ReadByte())!=-1)
cs.WriteByte((byte) data);

MessageBox.Show("Everything is OK", "OK");
// Close the crypto stream
memIn.Close();
cs.Close();
fsCrypt.Close();
}
catch (Exception xx)
{
MessageBox.Show("Encryption failed!\nSpecific Details: " + xx.ToString(), "Error");
}
}

}
}
[code]

Practice sesquipedalianism! Wink | ;)
AnswerRe: WinForms DataSet Read Encrypted XML ??? Pin
Heath Stewart10-Nov-03 6:22
protectorHeath Stewart10-Nov-03 6:22 
General&quot;Unspecified error&quot; when trying to open Visual Source Safe from Visual Studio 2003 .NET Pin
john5137-Nov-03 9:58
john5137-Nov-03 9:58 
GeneralJohn, Not sure if this will help Pin
E.L. Golpe10-Nov-03 5:59
E.L. Golpe10-Nov-03 5:59 
Generalflicker on resizing tabcontrols Pin
siegnagel7-Nov-03 0:45
siegnagel7-Nov-03 0:45 
GeneralMaybe same class of problem as this?? Pin
E.L. Golpe10-Nov-03 6:02
E.L. Golpe10-Nov-03 6:02 
GeneralKeyCodeV2 Pin
kersyanti6-Nov-03 20:10
kersyanti6-Nov-03 20:10 
QuestionManaged C++ server side executables ? Pin
Jerry Evans6-Nov-03 8:51
Jerry Evans6-Nov-03 8:51 
AnswerRe: Managed C++ server side executables ? Pin
leppie6-Nov-03 9:50
leppie6-Nov-03 9:50 
GeneralRe: Managed C++ server side executables ? Pin
Jerry Evans8-Nov-03 7:39
Jerry Evans8-Nov-03 7:39 
GeneralFrom MSDN Magazine, Sometime in the past... Pin
E.L. Golpe10-Nov-03 6:07
E.L. Golpe10-Nov-03 6:07 
GeneralRe: From MSDN Magazine, Sometime in the past... Pin
Jerry Evans10-Nov-03 6:55
Jerry Evans10-Nov-03 6:55 
GeneralRe: From MSDN Magazine, Sometime in the past... Pin
Heath Stewart10-Nov-03 7:37
protectorHeath Stewart10-Nov-03 7:37 
GeneralRe: From MSDN Magazine, Sometime in the past... Pin
Jerry Evans10-Nov-03 8:01
Jerry Evans10-Nov-03 8:01 
GeneralRe: From MSDN Magazine, Sometime in the past... Pin
Heath Stewart10-Nov-03 9:33
protectorHeath Stewart10-Nov-03 9:33 
GeneralRe: Managed C++ server side executables ? Pin
Heath Stewart10-Nov-03 6:09
protectorHeath Stewart10-Nov-03 6:09 
GeneralRe: Managed C++ server side executables ? Pin
Jerry Evans10-Nov-03 6:57
Jerry Evans10-Nov-03 6:57 
GeneralSetup Program Pin
kersyanti5-Nov-03 23:23
kersyanti5-Nov-03 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.