private void encryptMenuItem_Click(object sender, EventArgs e) { if (inputTextBox.Text.Length != 0) { openFileDialog.FileName = ""; openFileDialog.Title = "Open Public Key File"; openFileDialog.Filter = "Public Key Document( *.pke )|*.pke"; string fileString = null; if (openFileDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(openFileDialog.FileName)) { StreamReader streamReader = new StreamReader(openFileDialog.FileName, true); fileString = streamReader.ReadToEnd(); streamReader.Close(); if (fileString.Length >= inputTextBox.MaxLength) { MessageBox.Show("ERROR: \nThe file you are trying to open is too big for the text editor to display properly.\nPlease open a smaller document!\nOperation Aborted!"); } } } if (fileString != null) { FinishedProcessDelegate finishedProcessDelegate = new FinishedProcessDelegate(FinishedProcess); UpdateTextDelegate updateTextDelegate = new UpdateTextDelegate(UpdateText); string bitStrengthString = fileString.Substring(0, fileString.IndexOf("</BitStrength>") + 14); fileString = fileString.Replace(bitStrengthString, ""); int bitStrength = Convert.ToInt32(bitStrengthString.Replace("<BitStrength>", "").Replace("</BitStrength>", "")); Point point = new Point((inputTextBox.Size.Width / 2) - (panel.Size.Width / 2), (inputTextBox.Size.Height / 2) - (panel.Size.Height / 2)); panel.Location = point; panel.Visible = true; this.Refresh(); fileMenuItem.Enabled = false; editMenuItem.Enabled = false; formatMenuItem.Enabled = false; encryptionMenuItem.Enabled = false; helpMenuItem.Enabled = false; if (fileString != null) { try { EncryptionThread encryptionThread = new EncryptionThread(); Thread encryptThread = new Thread(encryptionThread.Encrypt); encryptThread.IsBackground = true; encryptThread.Start(new Object[] { this, finishedProcessDelegate, updateTextDelegate, inputTextBox.Text, bitStrength, fileString }); } catch (CryptographicException CEx) { MessageBox.Show("ERROR: \nOne of the following has occured.\nThe cryptographic service provider cannot be acquired.\nThe length of the text being encrypted is greater than the maximum allowed length.\nThe OAEP padding is not supported on this computer.\n" + "Exact error: " + CEx.Message); } catch (Exception Ex) { MessageBox.Show("ERROR: \n" + Ex.Message); } } } } else { MessageBox.Show("ERROR: You Can Not Encrypt A NULL Value!!!"); } }
private void rsaEncryptMenuItem_Click(object sender, EventArgs e) { if(inputTextBox.Text.Length != 0) { openFileDialog.FileName = ""; openFileDialog.Title = "Open Public Key File"; openFileDialog.Filter = "Public Key Document( *.pke )|*.pke"; string rsaKeyString = null; if(openFileDialog.ShowDialog() == DialogResult.OK) { if(File.Exists(openFileDialog.FileName)) { var streamReader = new StreamReader(openFileDialog.FileName, true); rsaKeyString = streamReader.ReadToEnd(); streamReader.Close(); if(rsaKeyString.Length >= inputTextBox.MaxLength) { MessageBox.Show("ERROR: \nThe file you are trying to open is too big for the text editor to display properly.\nPlease open a smaller document!\nOperation Aborted!"); } } } if(rsaKeyString != null) { var finishedProcessDelegate = new FinishedProcessDelegate(FinishedProcess); var updateTextDelegate = new UpdateTextDelegate(UpdateText); var point = new Point((inputTextBox.Size.Width / 2) - (panel.Size.Width / 2), (inputTextBox.Size.Height / 2) - (panel.Size.Height / 2)); panel.Location = point; panel.Visible = true; Refresh(); fileMenuItem.Enabled = false; editMenuItem.Enabled = false; formatMenuItem.Enabled = false; encryptionMenuItem.Enabled = false; helpMenuItem.Enabled = false; if(rsaKeyString != null) { try { var encryptionThread = new EncryptionThread(); var encryptThread = new Thread(encryptionThread.Encrypt); encryptThread.IsBackground = true; encryptThread.Start(new Object[] {this, finishedProcessDelegate, updateTextDelegate, inputTextBox.Text, rsaKeyString}); } catch(CryptographicException CEx) { MessageBox.Show("ERROR: \nOne of the following has occured.\nThe cryptographic service provider cannot be acquired.\nThe length of the text being encrypted is greater than the maximum allowed length.\nThe OAEP padding is not supported on this computer.\n" + "Exact error: " + CEx.Message); } catch(Exception Ex) { MessageBox.Show("ERROR: \n" + Ex.Message); } } } } else { MessageBox.Show("ERROR: You Can Not Encrypt A NULL Value!"); } }
private void decryptMenuItem_Click( object sender, EventArgs e ) { if( inputTextBox.Text.Length != 0 ) { openFileDialog.FileName = ""; openFileDialog.Title = "Open Private Key File"; openFileDialog.Filter = "Private Key Document( *.kez )|*.kez"; string fileString = null; if( openFileDialog.ShowDialog() == DialogResult.OK ) { if( File.Exists( openFileDialog.FileName ) ) { StreamReader streamReader = new StreamReader( openFileDialog.FileName, true ); fileString = streamReader.ReadToEnd(); streamReader.Close(); if( fileString.Length >= inputTextBox.MaxLength ) { MessageBox.Show( "ERROR: \nThe file you are trying to open is too big for the text editor to display properly.\nPlease open a smaller document!\nOperation Aborted!" ); } } } if( File.Exists( openFileDialog.FileName ) ) { string bitStrengthString = fileString.Substring( 0, fileString.IndexOf( "</BitStrength>" ) + 14 ); fileString = fileString.Replace( bitStrengthString, "" ); int bitStrength = Convert.ToInt32( bitStrengthString.Replace( "<BitStrength>", "" ).Replace( "</BitStrength>", "" ) ); Point point = new Point( ( inputTextBox.Size.Width / 2 ) - ( panel.Size.Width / 2 ), ( inputTextBox.Size.Height / 2 ) - ( panel.Size.Height / 2 ) ); panel.Location = point; panel.Visible = true; this.Refresh(); fileMenuItem.Enabled = false; editMenuItem.Enabled = false; formatMenuItem.Enabled = false; encryptionMenuItem.Enabled = false; helpMenuItem.Enabled = false; string tempStorage = inputTextBox.Text; if( fileString != null ) { FinishedProcessDelegate finishedProcessDelegate = new FinishedProcessDelegate( FinishedProcess ); UpdateTextDelegate updateTextDelegate = new UpdateTextDelegate( UpdateText ); try { EncryptionThread decryptionThread = new EncryptionThread(); Thread decryptThread = new Thread( decryptionThread.Decrypt ); decryptThread.IsBackground = true; decryptThread.Start( new Object[] { this, finishedProcessDelegate, updateTextDelegate, inputTextBox.Text, bitStrength, fileString } ); } catch( CryptographicException CEx ) { MessageBox.Show( "ERROR: \nOne of the following has occured.\nThe cryptographic service provider cannot be acquired.\nThe length of the text being encrypted is greater than the maximum allowed length.\nThe OAEP padding is not supported on this computer.\n" + "Exact error: " + CEx.Message ); } catch( Exception Ex ) { MessageBox.Show( "ERROR:\n" + Ex.Message ); SetText( tempStorage ); } } } } else { MessageBox.Show( "ERROR: You Can Not Decrypt A NULL Value!!!" ); } }