0% found this document useful (0 votes)
3 views

FINAL DOC Encryption -Secure Communication Using Public Key Infrastructure

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

FINAL DOC Encryption -Secure Communication Using Public Key Infrastructure

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 63

1.

ENCRYPTION SECURE COMMUNICATION USING PUBLIC KEY


INFRASTRUCTURE VIA TEXT EDITOR

1.1.INTRODUCTION

Network engineers and systems administrators have been using File Transfer Protocol
(FTP) to send files back and forth to and from remote systems since the early days of the
Internet. The File Transfer Protocol program is part of every reputable TCP/IP stack. Though
we've all grown used to using File Transfer Protocol for the bulk of our file transfer needs, using
it securely is becoming more important today than ever before.

Internet file transfer applications, such as File Transfer Protocol, were designed as simple
utilities, not as enterprise applications. File Transfer Protocol does not use encryption,
transferring sensitive data and passwords across the Internet in clear text. As a result, competing
products lack the security, reliability and flexibility.

Encryption has become a part and parcel of our lives and we have accepted the fact that
data is going to encrypted and decrypted at various stages. However, there is not a single
encryption algorithm followed everywhere.

This project entitled as “Secure Communication” is to implement the Advance


Encryption Standard or Rijndeal Algorithm through networking capabilities which is done in
java to make sure that cryptographic techniques can be implemented in multi-platform. So this
project explains an encryption algorithm Rijndeal Algorithm and makes you implement through
mathematical formulas.

This project is developed on client server technology. The client encrypts the file and sends to
the server. Other client will receives the file and decrypts the file.

1
1.2. ABSTRACT

Cryptography is one of the most important security technologies which used to secure the
data transmission and the data itself. As the time and challenge growth, the cryptography also
grows up with variety of encryption techniques and algorithms. Among the algorithms, one of
the most popular is the RSA. This thesis concentrates on the study of the PKI concept generally
and the RSA algorithm specifically. Furthermore, through this thesis we developed the prototype
of chat using Java Programming Language. The development process follows the seven
systematic phases of system development life cycle. At the end of the development, the
prototype of the application is come out readily to be tested. The prototype only covers the
transmitting and receiving chat messages between two parties (client and server).Each message,
it should be able to decrypt the cipher text back to the original plaintext. This thesis actually is
just a beginning step to discover the PKI system. The PKI system is very complex and
complicated. More resource, energy and time are needed to develop a complete PKI system.
Hopefully this thesis can be a stepping stone to go further and deeper in the world of information
security, focusing on encryption within PKI environment.

The prototype only covers the transmitting and receiving chat messages between two
parties (client and server).Each message, it should be able to decrypt the cipher text back to the
original plaintext. This thesis actually is just a beginning step to discover the PKI system. The
PKI system is very complex and complicated. More resource, energy and time are needed to
develop a complete PKI system. Hopefully this thesis can be a stepping stone to go further and
deeper in the world of information security, focusing on encryption within PKI environment.

2
2.SYSTEM ANALYSIS

2.1.EXISTING SYSTEM:

In the existing system, the encrypted key is send with the document .if the key is send
with document, any user can view the encrypted document with that key. it means the security
provided for the encryption is not handled properly. and also the key byte (encrypted key)
generate with random byte. without the user interaction the key byte is generated.

3
2.2.PROPOSED SYSTEM:

To overcome all the problems in the existing system, we develop an “encryption -secure
communication using public key infrastructure via tcp/ip network protocol” to ease the
operation.

A system is required which is being capable of elimination all the problems and become
useful to users and thus the new system is derived. here, user can set the byte of key manually.

4
3. HARDWARE AND SOFTWARE SPECIFICATION

3.1. Hardware Requirements

• SYSTEM : Pentium IV 2.4 GHz


• HARD DISK : 40 GB
• RAM : 256 MB

3.2. Software Requirements

• Operating system : Windows XP Professional


• Technology : Microsoft Visual Studio .Net 2010
• Coding Language : C#

5
4. MODULES AND MODULES DESCRIPTION

The project contains four main modules.

1. File
2. Edit
3. Format
4. Encryption
5. Decryption

File Menu : Create a new Text file , Open, save and save as , exit

Edit : Edit text file new or open document file

Format : Text style and formatting fonts option

Encryption: Both the client and server use this module. Actual encryption and decryption
takes place in this module. The input for this module is the source file name, destination file
name and key. It takes the source file, reads 8-bytes at a time and encrypts the data and stores
in the destination file.

Decryption: Both the client and server use this module. Actual encryption and decryption
takes place in this module. The input for this module is the source file name, destination file
name and key. It takes the source file, reads 8-bytes at a time and decrypts the data and stores
in the destination file.

6
5. SYSTEM DESIGN

5.1.SOFTWARE STRUCTURE

Software is fundamental characteristic of computer software. Software structure is to


decompose the complex groups of module into sub modules i.e., Process, Menus, Inputs and
Reports.

The most general form of the software structure is the network .The structure is the
network. The structure inside a complex processing node might consist of concurrent processes
executing in parallel and communication through some combination of shared variables.

Design Methodology:

Design is concerned with identifying software components, specifying relationships


among component, specifying software structure and providing a blue print for the
implementation phase.

Design consists of three types:

1. Architectural Design
2. Detail Design
3. External Design

Architectural Design

Architectural Design involves identifying the software components, decoupling and


decomposing them into processing modules and conceptual data structure and specifying
relationships among the components.

7
Detailed Design

Detailed design is concerned with the details of how to package the processing modules
and how to implement the processing algorithms, data structure and interconnection among
modules and data structure.

8
5.2.DATA FLOW DIAGRAM

9
Open

Save

10
11
5.3.UML DIAGRAMS:

Class Diagram:

12
5.4.SEQUENCE DIAGRAM:

Client Cipher TransferFile Server


: User

1: start

2: start 3: connect

4: connectionobject

5: encrypt 6: encrypt

7: cipherfile

8: sendfile

9: transferfile
10: writeFile

11: acknowledgement

12: decryptfile

13: decryptedfile

13
5.5. USE CASE DIAGRAMS:

Client Use Case Diagram

Server Use Case Diagram

14
DATABASE TABLE
Login
Fields Type
userid varchar(50)
username varchar(50)
Password varchar(50)

content

Fields Type
contentid varchar(50)
Nameofthecontent varchar(50)
description varchar(50)

Keyupload
Fields Type
keyid varchar(50)
Ksyname varchar(50)
encrypt varchar(50)
decrypt varchar(50)
accesscode varchar(50)

15
6. SOFTWARE ENVIRONMENT
7.
6.1.FEATURES OF .NET

Microsoft .NET is a set of Microsoft software technologies for rapidly building and
integrating XML Web services, Microsoft Windows-based applications, and Web solutions.
The .NET Framework is a language-neutral platform for writing programs that can easily and
securely interoperate. There’s no language barrier with .NET: there are numerous languages
available to the developer including Managed C++, C#, Visual Basic and Java Script. The .NET
framework provides the foundation for components to interact seamlessly, whether locally or
remotely on different platforms. It standardizes common data types and communications
protocols so that components created in different languages can easily interoperate.

“.NET” is also the collective name given to various software components built upon
the .NET platform. These will be both products (Visual Studio.NET and Windows.NET Server,
for instance) and services (like Passport, .NET My Services, and so on).

THE .NET FRAMEWORK

The .NET Framework has two main parts:

1. The Common Language Runtime (CLR).

2. A hierarchical set of class libraries.

The CLR is described as the “execution engine” of .NET. It provides the environment within
which programs run. The most important features are

 Conversion from a low-level assembler-style language, called Intermediate


Language (IL), into code native to the platform being executed on.
 Memory management, notably including garbage collection.
 Checking and enforcing security restrictions on the running code.
 Loading and executing programs, with version control and other such features.
 The following features of the .NET framework are also worth description:

16
Managed Code

The code that targets .NET, and which contains certain extra Information -“metadata” - to
describe itself. Whilst both managed and unmanaged code can run in the runtime, only managed
code contains the information that allows the CLR to guarantee, for instance, safe execution and
interoperability.

Managed Data

With Managed Code comes Managed Data. CLR provides memory allocation
and Deal location facilities, and garbage collection. Some .NET languages use Managed Data by
default, such as C#, Visual Basic.NET and JScript.NET, whereas others, namely C++, do not.
Targeting CLR can, depending on the language you’re using, impose certain constraints on the
features available. As with managed and unmanaged code, one can have both managed and
unmanaged data in .NET applications - data that doesn’t get garbage collected but instead is
looked after by unmanaged code.

Common Type System

The CLR uses something called the Common Type System (CTS) to strictly enforce
type-safety. This ensures that all classes are compatible with each other, by describing types in a
common way. CTS define how types work within the runtime, which enables types in one
language to interoperate with types in another language, including cross-language exception
handling. As well as ensuring that types are only used in appropriate ways, the runtime also
ensures that code doesn’t attempt to access memory that hasn’t been allocated to it.

Common Language Specification

The CLR provides built-in support for language interoperability. To ensure that you can
develop managed code that can be fully used by developers using any programming language, a
set of language features and rules for using them called the Common Language Specification
(CLS) has been defined. Components that follow these rules and expose only CLS features are
considered CLS-compliant.

17
THE CLASS LIBRARY

.NET provides a single-rooted hierarchy of classes, containing over 7000 types. The root
of the namespace is called System; this contains basic types like Byte, Double, Boolean, and
String, as well as Object. All objects derive from System. Object. As well as objects, there are
value types. Value types can be allocated on the stack, which can provide useful flexibility.
There are also efficient means of converting value types to object types if and when necessary.

The set of classes is pretty comprehensive, providing collections, file, screen, and
network I/O, threading, and so on, as well as XML and database connectivity.

The class library is subdivided into a number of sets (or namespaces), each providing
distinct areas of functionality, with dependencies between the namespaces kept to a minimum.

LANGUAGES SUPPORTED BY .NET

The multi-language capability of the .NET Framework and Visual Studio .NET enables
developers to use their existing programming skills to build all types of applications and XML
Web services. The .NET framework supports new versions of Microsoft’s old favorites Visual
Basic and C++ (as VB.NET and Managed C++), but there are also a number of new additions to
the family.

Visual Basic .NET has been updated to include many new and improved language
features that make it a powerful object-oriented programming language. These features include
inheritance, interfaces, and overloading, among others. Visual Basic also now supports
structured exception handling, custom attributes and also supports multi-threading.

Visual Basic .NET is also CLS compliant, which means that any CLS-compliant
language can use the classes, objects, and components you create in Visual Basic .NET.

Managed Extensions for C++ and attributed programming are just some of the
enhancements made to the C++ language. Managed Extensions simplify the task of migrating
existing C++ applications to the new .NET Framework.

C# is Microsoft’s new language. It’s a C-style language that is essentially “C++ for Rapid
Application Development”. Unlike other languages, its specification is just the grammar of the

18
language. It has no standard library of its own, and instead has been designed with the intention
of using the .NET libraries as its own.

Microsoft Visual J# .NET provides the easiest transition for Java-language developers
into the world of XML Web Services and dramatically improves the interoperability of Java-
language programs with existing software written in a variety of other programming languages.

Active State has created Visual Perl and Visual Python, which enable .NET-aware
applications to be built in either Perl or Python. Both products can be integrated into the Visual
Studio .NET environment. Visual Perl includes support for Active State’s Perl Dev Kit.

Other languages for which .NET compilers are available include

 FORTRAN
 COBOL
 Eiffel
Fig1 .Net Framework

ASP.NET Windows Forms

XML WEB SERVICES

Base Class Libraries

Common Language Runtime

Operating System

C#.NET is also compliant with CLS (Common Language Specification) and supports
structured exception handling. CLS is set of rules and constructs that are supported by the
CLR (Common Language Runtime). CLR is the runtime environment provided by the .NET
Framework; it manages the execution of the code and also makes the development process
easier by providing services.

C#.NET is a CLS-compliant language. Any objects, classes, or components that created


in C#.NET can be used in any other CLS-compliant language. In addition, we can use
19
objects, classes, and components created in other CLS-compliant languages in C#.NET .The
use of CLS ensures complete interoperability among applications, regardless of the languages
used to create the application.

CONSTRUCTORS AND DESTRUCTORS:

Constructors are used to initialize objects, whereas destructors are used to destroy them.
In other words, destructors are used to release the resources allocated to the object. In
C#.NET the sub finalize procedure is available. The sub finalize procedure is used to
complete the tasks that must be performed when an object is destroyed. The sub finalize
procedure is called automatically when an object is destroyed. In addition, the sub finalize
procedure can be called only from the class it belongs to or from derived classes.

GARBAGE COLLECTION

Garbage Collection is another new feature in C#.NET. The .NET Framework monitors
allocated resources, such as objects and variables. In addition, the .NET Framework
automatically releases memory for reuse by destroying objects that are no longer in use.

In C#.NET, the garbage collector checks for the objects that are not currently in use by
applications. When the garbage collector comes across an object that is marked for garbage
collection, it releases the memory occupied by the object.

OVERLOADING

Overloading is another feature in C#. Overloading enables us to define multiple procedures


with the same name, where each procedure has a different set of arguments. Besides using
overloading for procedures, we can use it for constructors and properties in a class.

MULTITHREADING:

C#.NET also supports multithreading. An application that supports multithreading can handle
multiple tasks simultaneously, we can use multithreading to decrease the time taken by an
application to respond to user interaction.

STRUCTURED EXCEPTION HANDLING

20
C#.NET supports structured handling, which enables us to detect and remove
errors at runtime. In C#.NET, we need to use Try…Catch…Finally statements to create
exception handlers. Using Try…Catch…Finally statements, we can create robust and
effective exception handlers to improve the performance of our application.

THE .NET FRAMEWORK

The .NET Framework is a new computing platform that simplifies application


development in the highly distributed environment of the Internet.

OBJECTIVES OF. NET FRAMEWORK

1. To provide a consistent object-oriented programming environment whether object codes is


stored and executed locally on Internet-distributed, or executed remotely.

2. To provide a code-execution environment to minimizes software deployment and


guarantees safe execution of code.

3. Eliminates the performance problems.

There are different types of application, such as Windows-based applications and Web-based
applications.

6.2. SQL-SERVER

The OLAP Services feature available in SQL Server version 7.0 is now called
SQL Server 2000 Analysis Services. The term OLAP Services has been replaced with the term
Analysis Services. Analysis Services also includes a new data mining component. The
Repository component available in SQL Server version 7.0 is now called Microsoft SQL Server
2000 Meta Data Services. References to the component now use the term Meta Data Services.
The term repository is used only in reference to the repository engine within Meta Data Services

SQL-SERVER database consist of six type of objects,

They are,

1. TABLE

21
2. QUERY
3. FORM
4. REPORT
5. MACRO
TABLE:

A database is a collection of data about a specific topic.

VIEWS OF TABLE:

We can work with a table in two types,

1. Design View

2. Datasheet View

Design View

To build or modify the structure of a table we work in the table design


view. We can specify what kind of data will be hold.

Datasheet View

To add, edit or analyses the data itself we work in tables datasheet view
mode.

QUERY:

A query is a question that has to be asked the data. Access gathers data that answers the
question from one or more table. The data that make up the answer is either dynaset (if you edit
it) or a snapshot (it cannot be edited).Each time we run query, we get latest information in the
dynaset. Access either displays the dynaset or snapshot for us to view or perform an action on it,
such as deleting or updating.

22
23
7. SYSTEM TESTING
7.1.INTRODUCTION

The purpose of testing is to discover errors. Testing is the process of trying to discover every
conceivable fault or weakness in a work product. It provides a way to check the functionality of
components, sub assemblies, assemblies and/or a finished product It is the process of exercising
software with the intent of ensuring that the

Software system meets its requirements and user expectations and does not fail in an
unacceptable manner. There are various types of test. Each test type addresses a specific testing
requirement.

7.1.TYPES OF TESTS
Unit testing
Unit testing involves the design of test cases that validate that the internal program logic is
functioning properly, and that program inputs produce valid outputs. All decision branches and
internal code flow should be validated. It is the testing of individual software units of the
application .it is done after the completion of an individual unit before integration. This is a
structural testing, that relies on knowledge of its construction and is invasive. Unit tests perform
basic tests at component level and test a specific business process, application, and/or system
configuration. Unit tests ensure that each unique path of a business process performs accurately
to the documented specifications and contains clearly defined inputs and expected results.

Integration testing
Integration tests are designed to test integrated software components to determine if they
actually run as one program. Testing is event driven and is more concerned with the basic
outcome of screens or fields. Integration tests demonstrate that although the components were
individually satisfaction, as shown by successfully unit testing, the combination of components is
correct and consistent. Integration testing is specifically aimed at exposing the problems that
arise from the combination of components.

24
Functional test
Functional tests provide systematic demonstrations that functions tested are available as
specified by the business and technical requirements, system documentation, and user manuals.

Functional testing is centered on the following items:

Valid Input : identified classes of valid input must be accepted.

Invalid Input : identified classes of invalid input must be rejected.

Functions : identified functions must be exercised.

Output : identified classes of application outputs must be exercised.

Systems/Procedures: interfacing systems or procedures must be invoked.

Organization and preparation of functional tests is focused on requirements, key functions, or


special test cases. In addition, systematic coverage pertaining to identify Business process flows;
data fields, predefined processes, and successive processes must be considered for testing.
Before functional testing is complete, additional tests are identified and the effective value of
current tests is determined.

System Test
System testing ensures that the entire integrated software system meets requirements. It tests a
configuration to ensure known and predictable results. An example of system testing is the
configuration oriented system integration test. System testing is based on process descriptions
and flows, emphasizing pre-driven process links and integration points.

Test strategy and approach


Field testing will be performed manually and functional tests will be written in detail.

Test objectives

 All field entries must work properly.


 Pages must be activated from the identified link.
 The entry screen, messages and responses must not be delayed.

25
Features to be tested

 Verify that the entries are of the correct format


 No duplicate entries should be allowed
 All links should take the user to the correct page.
6.2 Integration Testing
Software integration testing is the incremental integration testing of two or more
integrated software components on a single platform to produce failures caused by interface
defects.

The task of the integration test is to check that components or software applications, e.g.
components in a software system or – one step up – software applications at the company level –
interact without error.

Test Results: All the test cases mentioned above passed successfully. No defects encountered.

6.3 Acceptance Testing


User Acceptance Testing is a critical phase of any project and requires significant
participation by the end user. It also ensures that the system meets the functional requirements.

Test Results: All the test cases mentioned above passed successfully. No defects encountered.

26
8. CONCLUSION

Security in the Internet is improving. The increasing use of the Internet for commerce is
improving the deployed technology to protect the financial transactions. Extension of the basic
technologies to protect multicast communications is possible and can be expected to be deployed
as multicast becomes more widespread.

Control over routing remains the basic tool for controlling access to streams. Implementing
particular policies will be possible as multicast routing protocols improve. Cryptography is a tool
which may alleviate many of the perceived problems of using the secure for communications.
However, cryptography requires the safe implementation of complex mathematical equations
and protocols, and there are always worries about bad implementations. A further worry is that
users are integral to securing communications, since they must provide appropriate keys.

27
9. FUTURE ENHANCEMENT
The purpose of the Secure Communication Services is to provide a standard application
programming interface to certain communication-oriented security technologies. An
implementation of Secure Communication Services, together with the necessary cryptographic
algorithms and protocols, permits callers portably and interoperable* to counter a range of
vulnerabilities that may affect the security of communication between applications in open
networks.
General security objectives and best practices are listed. Particularly for the TCP/IP
protocol suite, a wide range of cryptography-based secure communication protocols is available.
The paper describes their principles and scope of application. Next, we focus on industrial
communication systems, which have a number of security-relevant characteristics distinct from
the office IT systems.

28
10.BIOGRAPHY
Good Teachers are worth more than thousand books, we have them in Our Department
References Made From:
1. User Interfaces in C#: Windows Forms and Custom Controls by Matthew MacDonald.

2. Applied Microsoft® .NET Framework Programming (Pro-Developer) by Jeffrey Richter.

3. Practical .Net2 and C#2: Harness the Platform, the Language, and the Framework by
Patrick Smacchia.

4. Data Communications and Networking, by Behrouz A Forouzan.

5. Computer Networking: A Top-Down Approach, by James F. Kurose.

6. Operating System Concepts,by Abraham Silberschatz.

7. M. Armbrust, A. Fox, R. Griffith, A. D. Joseph, R. H. Katz, A. Konwinski, G. Lee, D.


A. Patterson, A. Rabkin, I. Stoica, and M. Zaharia, “Above the clouds: A berkeley view
of cloud computing,” University of California, Berkeley, Tech. Rep. USB-EECS-2009-
28, Feb 2009.

8. “The apache cassandra project,” http://cassandra.apache.org/.

9. L. Lamport, “The part-time parliament,” ACM Transactions


on Computer Systems, vol. 16, pp. 133–169, 1998.

10. N. Bonvin, T. G. Papaioannou, and K. Aberer, “Cost-efficient

Sites Referred:
http://www.sourcefordgde.com
http://www.networkcomputing.com/

29
http://www.ieee.org

http://www.emule-project.net/

11.APPENDIX

10.1.SAMPLE SCREEN OUTPUT


Login

30
31
32
33
Encryption the Document

34
35
36
37
11.1.CODING
Login
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Encryption;

namespace RSACryptoPad
{
publicpartialclassfrmlogin1 : Form
{
public frmlogin1()
{
InitializeComponent();
}

privatevoid button1_Click(object sender, EventArgs e)


{
if (textBox1.Text == "admin"&& textBox2.Text == "admin")
{
MainForm frm = newMainForm();
this.Hide();
frm.Show();

}
else
{
MessageBox.Show("Login Error! Please try again");
}
}
}
}

Main form
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
using RSACryptoPad;

38
namespace Encryption
{
publicclassMainForm : Form
{
privateFontDialog fontDialog;
privateIContainer components;
privateLabel processingLabel;
privateMenuItem aboutMenuItem;
privateMenuItem copyMenuItem;
privateMenuItem cutMenuItem;
privateMenuItem decryptMenuItem;
privateMenuItem deleteMenuItem;
privateMenuItem editMenuItem;
privateMenuItem encryptionMenuItem;
privateMenuItem encryptMenuItem;
privateMenuItem exitMenuItem;
privateMenuItem fileMenuItem;
privateMenuItem fontMenuItem;
privateMenuItem formatMenuItem;
privateMenuItem generateKeyPairMenuItem;
privateMenuItem helpMenuItem;
privateMenuItem newFileMenuItem;
privateMenuItem openFileMenuItem;
privateMenuItem pasteMenuItem;
privateMenuItem saveAsFileMenuItem;
privateMenuItem saveMenuItem;
privateMenuItem selectAllmenuItem;
privateMenuItem separator1;
privateMenuItem separator2;
privateMenuItem separator3;
privateMenuItem undoMenuItem;
privateMenuItem wordWrapMenuItem;
privateMainMenu mainMenu;
privateOpenFileDialog openFileDialog;
privatePanel panel;
privatePictureBox pictureBox;
privateSaveFileDialog saveFileDialog;
privateTextBox inputTextBox;

publicstaticint currentBitStrength = 0;
privatebool cleanForm = true;
privateMenuItem logout;
privatestring currentFileName = "Untitled";

publicdelegatevoidFinishedProcessDelegate();
publicdelegatevoidUpdateBitStrengthDelegate(int bitStrength);
publicdelegatevoidUpdateTextDelegate(string inputText);

public MainForm()
{ InitializeComponent(); }

public MainForm(string fileName)


{
InitializeComponent();
if (File.Exists(fileName))
{

39
currentFileName = fileName;
StreamReader streamReader = newStreamReader(fileName, true);
SetText(streamReader.ReadToEnd());
streamReader.Close();
this.Text = GetFileName(fileName) + " - Encryption";
cleanForm = true;
}
}

protectedoverridevoid Dispose(bool disposing)


{
if (disposing)
{
if (components != null)
{ components.Dispose(); }
}
base.Dispose(disposing);
}

privatevoid InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.mainMenu = new System.Windows.Forms.MainMenu(this.components);
this.fileMenuItem = new System.Windows.Forms.MenuItem();
this.newFileMenuItem = new System.Windows.Forms.MenuItem();
this.openFileMenuItem = new System.Windows.Forms.MenuItem();
this.saveMenuItem = new System.Windows.Forms.MenuItem();
this.saveAsFileMenuItem = new System.Windows.Forms.MenuItem();
this.separator1 = new System.Windows.Forms.MenuItem();
this.exitMenuItem = new System.Windows.Forms.MenuItem();
this.editMenuItem = new System.Windows.Forms.MenuItem();
this.undoMenuItem = new System.Windows.Forms.MenuItem();
this.separator2 = new System.Windows.Forms.MenuItem();
this.cutMenuItem = new System.Windows.Forms.MenuItem();
this.copyMenuItem = new System.Windows.Forms.MenuItem();
this.pasteMenuItem = new System.Windows.Forms.MenuItem();
this.deleteMenuItem = new System.Windows.Forms.MenuItem();
this.separator3 = new System.Windows.Forms.MenuItem();
this.selectAllmenuItem = new System.Windows.Forms.MenuItem();
this.formatMenuItem = new System.Windows.Forms.MenuItem();
this.wordWrapMenuItem = new System.Windows.Forms.MenuItem();
this.fontMenuItem = new System.Windows.Forms.MenuItem();
this.encryptionMenuItem = new System.Windows.Forms.MenuItem();
this.encryptMenuItem = new System.Windows.Forms.MenuItem();
this.decryptMenuItem = new System.Windows.Forms.MenuItem();
this.generateKeyPairMenuItem = new System.Windows.Forms.MenuItem();
this.helpMenuItem = new System.Windows.Forms.MenuItem();
this.aboutMenuItem = new System.Windows.Forms.MenuItem();
this.logout = new System.Windows.Forms.MenuItem();
this.inputTextBox = new System.Windows.Forms.TextBox();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.fontDialog = new System.Windows.Forms.FontDialog();
this.panel = new System.Windows.Forms.Panel();

40
this.processingLabel = new System.Windows.Forms.Label();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.fileMenuItem,
this.editMenuItem,
this.formatMenuItem,
this.encryptionMenuItem,
this.helpMenuItem,
this.logout});
//
// fileMenuItem
//
this.fileMenuItem.Index = 0;
this.fileMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.newFileMenuItem,
this.openFileMenuItem,
this.saveMenuItem,
this.saveAsFileMenuItem,
this.separator1,
this.exitMenuItem});
this.fileMenuItem.Text = "File";
//
// newFileMenuItem
//
this.newFileMenuItem.Index = 0;
this.newFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.newFileMenuItem.Text = "New";
this.newFileMenuItem.Click += new System.EventHandler(this.newFileMenuItem_Click);
//
// openFileMenuItem
//
this.openFileMenuItem.Index = 1;
this.openFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.openFileMenuItem.Text = "Open...";
this.openFileMenuItem.Click += new System.EventHandler(this.openFileMenuItem_Click);
//
// saveMenuItem
//
this.saveMenuItem.Index = 2;
this.saveMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.saveMenuItem.Text = "Save...";
this.saveMenuItem.Click += new System.EventHandler(this.saveMenuItem_Click);
//
// saveAsFileMenuItem
//
this.saveAsFileMenuItem.Index = 3;
this.saveAsFileMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.saveAsFileMenuItem.Text = "Save As... ";
this.saveAsFileMenuItem.Click += new System.EventHandler(this.saveAsFileMenuItem_Click);
//

41
// separator1
//
this.separator1.Index = 4;
this.separator1.Text = "-";
//
// exitMenuItem
//
this.exitMenuItem.Index = 5;
this.exitMenuItem.Text = "Exit ";
this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);
//
// editMenuItem
//
this.editMenuItem.Index = 1;
this.editMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.undoMenuItem,
this.separator2,
this.cutMenuItem,
this.copyMenuItem,
this.pasteMenuItem,
this.deleteMenuItem,
this.separator3,
this.selectAllmenuItem});
this.editMenuItem.Text = "Edit";
//
// undoMenuItem
//
this.undoMenuItem.Index = 0;
this.undoMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
this.undoMenuItem.Text = "Undo";
this.undoMenuItem.Click += new System.EventHandler(this.undoMenuItem_Click);
//
// separator2
//
this.separator2.Index = 1;
this.separator2.Text = "-";
//
// cutMenuItem
//
this.cutMenuItem.Index = 2;
this.cutMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.cutMenuItem.Text = "Cut";
this.cutMenuItem.Click += new System.EventHandler(this.cutMenuItem_Click);
//
// copyMenuItem
//
this.copyMenuItem.Index = 3;
this.copyMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.copyMenuItem.Text = "Copy";
this.copyMenuItem.Click += new System.EventHandler(this.copyMenuItem_Click);
//
// pasteMenuItem
//
this.pasteMenuItem.Index = 4;
this.pasteMenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.pasteMenuItem.Text = "Paste";

42
this.pasteMenuItem.Click += new System.EventHandler(this.pasteMenuItem_Click);
//
// deleteMenuItem
//
this.deleteMenuItem.Index = 5;
this.deleteMenuItem.Shortcut = System.Windows.Forms.Shortcut.Del;
this.deleteMenuItem.Text = "Delete";
this.deleteMenuItem.Click += new System.EventHandler(this.deleteMenuItem_Click);
//
// separator3
//
this.separator3.Index = 6;
this.separator3.Text = "-";
//
// selectAllmenuItem
//
this.selectAllmenuItem.Index = 7;
this.selectAllmenuItem.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.selectAllmenuItem.Text = "Select All";
this.selectAllmenuItem.Click += new System.EventHandler(this.selectAllmenuItem_Click);
//
// formatMenuItem
//
this.formatMenuItem.Index = 2;
this.formatMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.wordWrapMenuItem,
this.fontMenuItem});
this.formatMenuItem.Text = "Format";
//
// wordWrapMenuItem
//
this.wordWrapMenuItem.Checked = true;
this.wordWrapMenuItem.Index = 0;
this.wordWrapMenuItem.RadioCheck = true;
this.wordWrapMenuItem.Text = "Word Wrap";
this.wordWrapMenuItem.Click += new System.EventHandler(this.wordWrapMenuItem_Click);
//
// fontMenuItem
//
this.fontMenuItem.Index = 1;
this.fontMenuItem.Text = "Font...";
this.fontMenuItem.Click += new System.EventHandler(this.fontMenuItem_Click);
//
// encryptionMenuItem
//
this.encryptionMenuItem.Index = 3;
this.encryptionMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.encryptMenuItem,
this.decryptMenuItem,
this.generateKeyPairMenuItem});
this.encryptionMenuItem.Text = "Encryption";
//
// encryptMenuItem
//
this.encryptMenuItem.Index = 0;
this.encryptMenuItem.Text = "Encrypt...";

43
this.encryptMenuItem.Click += new System.EventHandler(this.encryptMenuItem_Click);
//
// decryptMenuItem
//
this.decryptMenuItem.Index = 1;
this.decryptMenuItem.Text = "Decrypt...";
this.decryptMenuItem.Click += new System.EventHandler(this.decryptMenuItem_Click);
//
// generateKeyPairMenuItem
//
this.generateKeyPairMenuItem.Index = 2;
this.generateKeyPairMenuItem.Text = "Generate Key Pair...";
this.generateKeyPairMenuItem.Click += new System.EventHandler(this.generateKeyPairMenuItem_Click);
//
// helpMenuItem
//
this.helpMenuItem.Index = 4;
this.helpMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.aboutMenuItem});
this.helpMenuItem.Text = "Help";
//
// aboutMenuItem
//
this.aboutMenuItem.Index = 0;
this.aboutMenuItem.Text = "About Encryption";
this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
//
// logout
//
this.logout.Index = 5;
this.logout.Text = "Logout";
this.logout.Click += new System.EventHandler(this.logout_Click);
//
// inputTextBox
//
this.inputTextBox.AcceptsReturn = true;
this.inputTextBox.AcceptsTab = true;
this.inputTextBox.AllowDrop = true;
this.inputTextBox.BackColor = System.Drawing.Color.Teal;
this.inputTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.inputTextBox.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.inputTextBox.ForeColor = System.Drawing.Color.White;
this.inputTextBox.Location = new System.Drawing.Point(0, 0);
this.inputTextBox.Multiline = true;
this.inputTextBox.Name = "inputTextBox";
this.inputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.inputTextBox.Size = new System.Drawing.Size(634, 405);
this.inputTextBox.TabIndex = 1;
this.inputTextBox.TabStop = false;
this.inputTextBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.inputTextBox_DragDrop);
this.inputTextBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.inputTextBox_DragEnter);
this.inputTextBox.TextChanged += new System.EventHandler(this.inputTextBox_TextChanged);
//
// fontDialog
//

44
this.fontDialog.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.fontDialog.FontMustExist = true;
this.fontDialog.ShowEffects = false;
//
// panel
//
this.panel.BackColor = System.Drawing.Color.Black;
this.panel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel.Controls.Add(this.processingLabel);
this.panel.Controls.Add(this.pictureBox);
this.panel.ForeColor = System.Drawing.Color.Lime;
this.panel.Location = new System.Drawing.Point(-1, 411);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(200, 82);
this.panel.TabIndex = 0;
this.panel.Visible = false;
//
// processingLabel
//
this.processingLabel.Location = new System.Drawing.Point(8, 48);
this.processingLabel.Name = "processingLabel";
this.processingLabel.Size = new System.Drawing.Size(184, 23);
this.processingLabel.TabIndex = 0;
this.processingLabel.Text = "Processing please wait...";
//
// pictureBox
//
this.pictureBox.BackColor = System.Drawing.Color.Black;
this.pictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image")));
this.pictureBox.Location = new System.Drawing.Point(80, 8);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(32, 34);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 19);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(632, 404);
this.Controls.Add(this.panel);
this.Controls.Add(this.inputTextBox);
this.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Menu = this.mainMenu;
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.mainForm_FormClosing);
this.Load += new System.EventHandler(this.mainForm_Load);
this.panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

45
}

[STAThread]
publicstaticvoid Main(string[] args)
{
Application.EnableVisualStyles();
if (args.Length > 0)
{
Application.Run(newfrmlogin1());
}
else
{
Application.Run(newfrmlogin1());
}
}

privatevoid FinishedProcess()
{
panel.Visible = false;
fileMenuItem.Enabled = true;
editMenuItem.Enabled = true;
formatMenuItem.Enabled = true;
encryptionMenuItem.Enabled = true;
helpMenuItem.Enabled = true;
Application.DoEvents();
}

publicstaticvoid SetBitStrength(int bitStrength)


{ currentBitStrength = bitStrength; }

privatevoid UpdateText(string inputText)


{ inputTextBox.Text = inputText; }

privatestring GetFileName(string fileName)


{
string[] fileParts = fileName.Split("\\".ToCharArray());
return fileParts[fileParts.Length - 1];
}

privatevoid SetText(string text)


{
this.inputTextBox.TextChanged -= new System.EventHandler(this.inputTextBox_TextChanged);
inputTextBox.Text = text;
this.inputTextBox.TextChanged += new System.EventHandler(this.inputTextBox_TextChanged);
}

privateSettings GetSettings()
{
Settings settings = null;
if (File.Exists("Settings.bin"))
{
StreamReader streamReader = newStreamReader("Settings.bin");
BinaryFormatter binaryFormatter = newBinaryFormatter();
settings = (Settings)binaryFormatter.Deserialize(streamReader.BaseStream);
streamReader.Close();
}

46
return settings;
}

privatevoid SaveSettings(string settingChanged)


{
Settings settings = newSettings();
if (File.Exists("Settings.bin"))
{
StreamReader streamReader = newStreamReader("Settings.bin");
BinaryFormatter binaryFormatter = newBinaryFormatter();
settings = (Settings)binaryFormatter.Deserialize(streamReader.BaseStream);
streamReader.Close();
switch (settingChanged)
{
case"LOCATION":
{
settings.Location = this.Location;
break;
}
case"SIZE":
{
settings.Width = this.Width;
settings.Height = this.Height;
break;
}
case"FONT":
{
settings.Font = inputTextBox.Font;
break;
}
case"WRAPPING":
{
settings.Wrapping = inputTextBox.WordWrap;
break;
}
}
StreamWriter streamWriter = newStreamWriter("Settings.bin", false);
binaryFormatter.Serialize(streamWriter.BaseStream, settings);
streamWriter.Close();
}
else
{
settings.Location = this.Location;
settings.Width = this.Width;
settings.Height = this.Height;
settings.Font = inputTextBox.Font;
settings.Wrapping = inputTextBox.WordWrap;
StreamWriter streamWriter = newStreamWriter("Settings.bin", false);
BinaryFormatter binaryFormatter = newBinaryFormatter();
binaryFormatter.Serialize(streamWriter.BaseStream, settings);
streamWriter.Close();
}
}

privatestring openFile(string title, string filterString)


{

47
openFileDialog.FileName = "";
openFileDialog.Title = title;
openFileDialog.Filter = filterString;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openFileDialog.FileName))
{
StreamReader streamReader = newStreamReader(openFileDialog.FileName, true);
string 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!");
returnnull;
}
if (fileString != null)
{
this.Text = GetFileName(openFileDialog.FileName) + " - Encryption";
currentFileName = openFileDialog.FileName;
}
return fileString;
}
}
returnnull;
}

privatebool saveFile()
{
saveFileDialog.Title = "Save As";
saveFileDialog.FileName = "*.txt";
saveFileDialog.Filter = "Text Document( *.txt )|*.txt|All Files|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
StreamWriter streamWriter = newStreamWriter(saveFileDialog.FileName, false);
streamWriter.Write(inputTextBox.Text);
streamWriter.Close();
this.Text = GetFileName(saveFileDialog.FileName) + " - Encryption";
currentFileName = saveFileDialog.FileName;
returntrue;
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
returnfalse;
}
}
returnfalse;
}

privatebool saveFile(string title, string filterString, string outputString)


{
saveFileDialog.Title = title;
saveFileDialog.Filter = filterString;

48
saveFileDialog.FileName = "";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
StreamWriter streamWriter = newStreamWriter(saveFileDialog.FileName, false);
if (outputString != null)
{ streamWriter.Write(outputString); }
streamWriter.Close();
returntrue;
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
returnfalse;
}
}
returnfalse;
}

privatevoid mainForm_Load(object sender, EventArgs e)


{
if (File.Exists("Settings.bin"))
{
Settings settings = GetSettings();
this.Location = settings.Location;
this.Width = settings.Width;
this.Height = settings.Height;
inputTextBox.Font = settings.Font;
inputTextBox.WordWrap = settings.Wrapping;
wordWrapMenuItem.Checked = (settings.Wrapping == true) ? true : false;
}
this.Text = GetFileName(currentFileName) + " - Encryption";
inputTextBox.Focus();
this.Resize += new System.EventHandler(this.mainForm_Resize);
this.Move += new System.EventHandler(this.MainForm_Move);
inputTextBox.Height = this.Size.Height - 53;
inputTextBox.Width = this.Size.Width - 7;
}

privatevoid mainForm_Resize(object sender, EventArgs e)


{
inputTextBox.Height = this.Size.Height - 53;
inputTextBox.Width = this.Size.Width - 7;
SaveSettings("SIZE");
}

privatevoid MainForm_Move(object sender, EventArgs e)


{ SaveSettings("LOCATION"); }

privatevoid mainForm_FormClosing(object sender, FormClosingEventArgs e)


{
this.Resize -= newEventHandler(this.mainForm_Resize);
this.Move -= newEventHandler(this.MainForm_Move);
if (!cleanForm)
{

49
string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine +
Environment.NewLine + "Do you want to save the changes?";
switch (MessageBox.Show(dialogText, "Encryption", MessageBoxButtons.YesNoCancel))
{
caseDialogResult.Yes:
{
if (!saveFile()) { e.Cancel = true; }
break;
}
caseDialogResult.Cancel:
{
e.Cancel = true;
break;
}
}
}
}

privatevoid inputTextBox_TextChanged(object sender, EventArgs e)


{
if (currentFileName.Equals("Untitled"))
{ cleanForm = (!inputTextBox.Text.Equals("")) ? false : true; }
else
{ cleanForm = false; }
}

privatevoid inputTextBox_DragEnter(object sender, DragEventArgs e)


{ e.Effect = DragDropEffects.All; }

privatevoid inputTextBox_DragDrop(object sender, DragEventArgs e)


{
bool clean = false;
if (!cleanForm)
{
string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine +
Environment.NewLine + "Do you want to save the changes?";
switch (MessageBox.Show(dialogText, "Encryption", MessageBoxButtons.YesNoCancel))
{
caseDialogResult.Yes:
{
if (saveFile()) { clean = true; }
break;
}
caseDialogResult.No:
{
clean = true;
break;
}
}
}
else
{ clean = true; }
if (clean)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, true) == true)
{

50
string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
StreamReader streamReader = newStreamReader(fileNames[0], true);
string fileContents = streamReader.ReadToEnd();
streamReader.Close();
currentFileName = fileNames[0];
this.Text = GetFileName(fileNames[0]) + " - Encryption";
SetText(fileContents);
cleanForm = true;
}
}
}

privatevoid newFileMenuItem_Click(object sender, EventArgs e)


{
if (!cleanForm)
{
string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine +
Environment.NewLine + "Do you want to save the changes?";
switch (MessageBox.Show(dialogText, "Encryption", MessageBoxButtons.YesNoCancel))
{
caseDialogResult.Yes:
{
if (saveFile())
{
SetText("");
currentFileName = "Untitled";
this.Text = "Untitled - Encryption";
cleanForm = true;
}
break;
}
caseDialogResult.No:
{
SetText("");
currentFileName = "Untitled";
this.Text = "Untitled - Encryption";
cleanForm = true;
break;
}
caseDialogResult.Cancel:
{ break; }
default:
{ break; }
}
}
else
{
SetText("");
currentFileName = "Untitled";
this.Text = "Untitled - Encryption";
}
}

privatevoid openFileMenuItem_Click(object sender, EventArgs e)


{
if (!cleanForm)

51
{
string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine +
Environment.NewLine + "Do you want to save the changes?";
switch (MessageBox.Show(dialogText, "Encryption", MessageBoxButtons.YesNoCancel))
{
caseDialogResult.Yes:
{
if (saveFile()) { SetText(""); }
else
{ return; }
break;
}
caseDialogResult.No:
{
SetText("");
break;
}
caseDialogResult.Cancel:
{ return; }
default:
{ break; }
}
}
try
{
string fileString = openFile("Open", "Text Document( *.txt )|*.txt|All Files|*.*");
if (fileString != null)
{
SetText(fileString);
cleanForm = true;
}
}
catch (Exception Ex) { MessageBox.Show("ERROR: \n" + Ex.Message); }
}

privatevoid saveAsFileMenuItem_Click(object sender, EventArgs e)


{
if (saveFile())
{
cleanForm = true;
this.Text = GetFileName(currentFileName) + " - Encryption";
}
}

privatevoid saveMenuItem_Click(object sender, EventArgs e)


{
if (currentFileName.Equals("Untitled"))
{
if (saveFile()) { cleanForm = true; }
}
else
{
try
{
StreamWriter streamWriter = newStreamWriter(currentFileName);
streamWriter.Write(inputTextBox.Text);

52
streamWriter.Flush();
streamWriter.Close();
cleanForm = true;
}
catch (Exception Ex)
{ MessageBox.Show("ERROR: \n" + Ex.Message); }
}
}

privatevoid exitMenuItem_Click(object sender, EventArgs e)


{
//Encryption.frmlogin1 log = new frmlogin1 ();
//log.MdiParent = this;
//this.Hide();
//log.Show();//if (!cleanForm)
//{
// string dialogText = "The text in the " + currentFileName + " file has changed." + Environment.NewLine +
Environment.NewLine + "Do you want to save the changes?";
// switch (MessageBox.Show(dialogText, "Encryption", MessageBoxButtons.YesNoCancel))
// {
// case DialogResult.Yes:
// {
// if (saveFile()) { Dispose(true); }
// break;
// }
// case DialogResult.No:
// {
// Dispose(true);
// break;
// }
// case DialogResult.Cancel:
// { break; }
// default:
// { break; }
// }
//}
//else
//{ Dispose(true); }
//Application.Close();
//Encriptions.Login = new Login();
//this.MdiParent = this;
//this.Hide();
//log.Show();
}

privatevoid undoMenuItem_Click(object sender, EventArgs e)


{ inputTextBox.Undo(); }

privatevoid cutMenuItem_Click(object sender, EventArgs e)


{
try { inputTextBox.Cut(); }
catch (Exception Ex)
{ Console.WriteLine(Ex.Message); }
}

privatevoid copyMenuItem_Click(object sender, EventArgs e)

53
{
try { inputTextBox.Copy(); }
catch (Exception Ex) { Console.WriteLine(Ex.Message); }
}

privatevoid pasteMenuItem_Click(object sender, EventArgs e)


{
try { inputTextBox.Paste(); }
catch (Exception Ex) { Console.WriteLine(Ex.Message); }
}

privatevoid deleteMenuItem_Click(object sender, EventArgs e)


{
if ((inputTextBox.Text.Length != 0) & (inputTextBox.SelectionStart != inputTextBox.Text.Length))
{
if (!inputTextBox.SelectedText.Equals(""))
{
try
{
int cursorPosition = inputTextBox.SelectionStart;
inputTextBox.Text = inputTextBox.Text.Remove(cursorPosition,
inputTextBox.SelectedText.Length);
inputTextBox.SelectionStart = cursorPosition;
}
catch (Exception Ex) { Console.WriteLine(Ex.Message); }
}
else
{
try
{
int cursorPosition = inputTextBox.SelectionStart;
inputTextBox.Text = inputTextBox.Text.Remove(cursorPosition, 1);
inputTextBox.SelectionStart = cursorPosition;
}
catch (Exception Ex) { Console.WriteLine(Ex.Message); }
}
}
}

privatevoid selectAllmenuItem_Click(object sender, EventArgs e)


{
try { inputTextBox.SelectAll(); }
catch (Exception Ex) { Console.WriteLine(Ex.Message); }
}

privatevoid wordWrapMenuItem_Click(object sender, EventArgs e)


{
if (wordWrapMenuItem.Checked == true)
{
wordWrapMenuItem.Checked = false;
inputTextBox.WordWrap = false;
}
else
{
wordWrapMenuItem.Checked = true;
inputTextBox.WordWrap = true;

54
}
SaveSettings("WRAPPING");
}

privatevoid fontMenuItem_Click(object sender, EventArgs e)


{
if (fontDialog.ShowDialog() == DialogResult.OK)
{
inputTextBox.Font = fontDialog.Font;
SaveSettings("FONT");
}
}

privatevoid 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 = newStreamReader(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 = newPoint((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 = newFinishedProcessDelegate(FinishedProcess);
UpdateTextDelegate updateTextDelegate = newUpdateTextDelegate(UpdateText);
try
{
EncryptionThread decryptionThread = newEncryptionThread();

55
Thread decryptThread = newThread(decryptionThread.Decrypt);
decryptThread.IsBackground = true;
decryptThread.Start(newObject[] { 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!!!"); }
}

privatevoid 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 = newStreamReader(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 = newFinishedProcessDelegate(FinishedProcess);
UpdateTextDelegate updateTextDelegate = newUpdateTextDelegate(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 = newPoint((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;

56
encryptionMenuItem.Enabled = false;
helpMenuItem.Enabled = false;
if (fileString != null)
{
try
{
EncryptionThread encryptionThread = newEncryptionThread();
Thread encryptThread = newThread(encryptionThread.Encrypt);
encryptThread.IsBackground = true;
encryptThread.Start(newObject[] { 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!!!"); }
}

privatevoid generateKeyPairMenuItem_Click(object sender, EventArgs e)


{
KeyPairGeneratorForm generator = newKeyPairGeneratorForm();
if (generator.ShowDialog() == DialogResult.OK)
{
RSACryptoServiceProvider RSAProvider = newRSACryptoServiceProvider(currentBitStrength);
string publicAndPrivateKeys = "<BitStrength>" + currentBitStrength.ToString() + "</BitStrength>" +
RSAProvider.ToXmlString(true);
string justPublicKey = "<BitStrength>" + currentBitStrength.ToString() + "</BitStrength>" +
RSAProvider.ToXmlString(false);
if (saveFile("Save Public/Private Keys As", "Public/Private Keys Document( *.kez )|*.kez",
publicAndPrivateKeys))
{ while (!saveFile("Save Public Key As", "Public Key Document( *.pke )|*.pke", justPublicKey)) { ; } }
}
}

privatevoid aboutMenuItem_Click(object sender, EventArgs e)


{
AboutForm aboutEncryption = newAboutForm();
aboutEncryption.ShowDialog(this);
}

privatevoid logout_Click(object sender, EventArgs e)


{
//frmlogin1 log = new frmlogin1();
//log.MdiParent = this;
//this.Hide();
this.Close();
}

57
}
}

About us
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Forms;

namespace Encryption
{
publicclassAboutForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label descriptionLabel;
private System.Windows.Forms.Label disclaimerLabel;
private System.Windows.Forms.GroupBox disclaimerGroupBox;
private System.Windows.Forms.PictureBox iconPictureBox;
privateLabel nameLabel;
private System.ComponentModel.Container components = null;

public AboutForm()
{InitializeComponent();}

protectedoverridevoid Dispose( bool disposing )


{
if( disposing )
{
if( components != null )
{components.Dispose();}
}
base.Dispose( disposing );
}

privatevoid InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
this.iconPictureBox = new System.Windows.Forms.PictureBox();
this.descriptionLabel = new System.Windows.Forms.Label();
this.disclaimerGroupBox = new System.Windows.Forms.GroupBox();
this.disclaimerLabel = new System.Windows.Forms.Label();
this.nameLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).BeginInit();
this.disclaimerGroupBox.SuspendLayout();
this.SuspendLayout();
//
// iconPictureBox
//
this.iconPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("iconPictureBox.Image")));
this.iconPictureBox.Location = new System.Drawing.Point(8, 16);

58
this.iconPictureBox.Name = "iconPictureBox";
this.iconPictureBox.Size = new System.Drawing.Size(32, 34);
this.iconPictureBox.TabIndex = 0;
this.iconPictureBox.TabStop = false;
//
// descriptionLabel
//
this.descriptionLabel.Font = new System.Drawing.Font("Georgia", 9.75F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.descriptionLabel.ForeColor = System.Drawing.SystemColors.ControlText;
this.descriptionLabel.Location = new System.Drawing.Point(56, 23);
this.descriptionLabel.Name = "descriptionLabel";
this.descriptionLabel.Size = new System.Drawing.Size(135, 22);
this.descriptionLabel.TabIndex = 0;
this.descriptionLabel.Text = "Encryption";
//
// disclaimerGroupBox
//
this.disclaimerGroupBox.Controls.Add(this.disclaimerLabel);
this.disclaimerGroupBox.Location = new System.Drawing.Point(8, 59);
this.disclaimerGroupBox.Name = "disclaimerGroupBox";
this.disclaimerGroupBox.Size = new System.Drawing.Size(384, 112);
this.disclaimerGroupBox.TabIndex = 1;
this.disclaimerGroupBox.TabStop = false;
this.disclaimerGroupBox.Text = "Disclaimer";
//
// disclaimerLabel
//
this.disclaimerLabel.Font = new System.Drawing.Font("Georgia", 8.25F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.disclaimerLabel.ForeColor = System.Drawing.Color.Black;
this.disclaimerLabel.Location = new System.Drawing.Point(6, 21);
this.disclaimerLabel.Name = "disclaimerLabel";
this.disclaimerLabel.Size = new System.Drawing.Size(420, 88);
this.disclaimerLabel.TabIndex = 0;
this.disclaimerLabel.Text = resources.GetString("disclaimerLabel.Text");
this.disclaimerLabel.Click += new System.EventHandler(this.disclaimerLabel_Click);
//
// nameLabel
//
this.nameLabel.Font = new System.Drawing.Font("Georgia", 9.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.nameLabel.ForeColor = System.Drawing.Color.Black;
this.nameLabel.Location = new System.Drawing.Point(8, 187);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(192, 16);
this.nameLabel.TabIndex = 2;
this.nameLabel.Text = " By: Mathew John Schlabaugh";
//
// AboutForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 19);
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(437, 216);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.disclaimerGroupBox);

59
this.Controls.Add(this.descriptionLabel);
this.Controls.Add(this.iconPictureBox);
this.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.Color.White;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AboutForm";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "About Encryption";
((System.ComponentModel.ISupportInitialize)(this.iconPictureBox)).EndInit();
this.disclaimerGroupBox.ResumeLayout(false);
this.ResumeLayout(false);

privatevoid disclaimerLabel_Click(object sender, EventArgs e)


{

}
}
}

Key Genration
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Encryption
{
publicclassKeyPairGeneratorForm: System.Windows.Forms.Form
{
private System.Windows.Forms.Button generateKeysButton;
private System.Windows.Forms.NumericUpDown numericUpDown;
private System.Windows.Forms.PictureBox keyPictureBox;
private System.ComponentModel.Container components = null;

public KeyPairGeneratorForm()
{ InitializeComponent(); }

protectedoverridevoid Dispose( bool disposing )


{
if( disposing )
{
if( components != null )
{ components.Dispose(); }
}
base.Dispose( disposing );

60
}

privatevoid InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(KeyPairGeneratorForm));
this.generateKeysButton = new System.Windows.Forms.Button();
this.keyPictureBox = new System.Windows.Forms.PictureBox();
this.numericUpDown = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.keyPictureBox)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).BeginInit();
this.SuspendLayout();
//
// generateKeysButton
//
this.generateKeysButton.BackColor = System.Drawing.SystemColors.Control;
this.generateKeysButton.Font = new System.Drawing.Font("Georgia", 8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.generateKeysButton.ForeColor = System.Drawing.Color.Black;
this.generateKeysButton.Location = new System.Drawing.Point(183, 119);
this.generateKeysButton.Name = "generateKeysButton";
this.generateKeysButton.Size = new System.Drawing.Size(149, 28);
this.generateKeysButton.TabIndex = 0;
this.generateKeysButton.Text = "Generate Keys";
this.generateKeysButton.UseVisualStyleBackColor = false;
this.generateKeysButton.Click += new System.EventHandler(this.generateKeysButton_Click);
//
// keyPictureBox
//
this.keyPictureBox.BackColor = System.Drawing.Color.Black;
this.keyPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.keyPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("keyPictureBox.Image")));
this.keyPictureBox.Location = new System.Drawing.Point(31, 61);
this.keyPictureBox.Name = "keyPictureBox";
this.keyPictureBox.Size = new System.Drawing.Size(66, 75);
this.keyPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.keyPictureBox.TabIndex = 1;
this.keyPictureBox.TabStop = false;
//
// numericUpDown
//
this.numericUpDown.BackColor = System.Drawing.Color.White;
this.numericUpDown.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.numericUpDown.ForeColor = System.Drawing.Color.Black;
this.numericUpDown.Increment = newdecimal(newint[] {
8,
0,
0,
0});
this.numericUpDown.Location = new System.Drawing.Point(183, 52);
this.numericUpDown.Maximum = newdecimal(newint[] {
16384,
0,
0,

61
0});
this.numericUpDown.Minimum = newdecimal(newint[] {
384,
0,
0,
0});
this.numericUpDown.Name = "numericUpDown";
this.numericUpDown.ReadOnly = true;
this.numericUpDown.Size = new System.Drawing.Size(149, 26);
this.numericUpDown.TabIndex = 0;
this.numericUpDown.ThousandsSeparator = true;
this.numericUpDown.UpDownAlign = System.Windows.Forms.LeftRightAlignment.Left;
this.numericUpDown.Value = newdecimal(newint[] {
1024,
0,
0,
0});
//
// KeyPairGeneratorForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 19);
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(366, 205);
this.Controls.Add(this.numericUpDown);
this.Controls.Add(this.keyPictureBox);
this.Controls.Add(this.generateKeysButton);
this.Font = new System.Drawing.Font("Georgia", 12F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.Color.White;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "KeyPairGeneratorForm";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Generate Keys";
this.Load += new System.EventHandler(this.KeyPairGeneratorForm_Load);
((System.ComponentModel.ISupportInitialize)(this.keyPictureBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

privatevoid generateKeysButton_Click( object sender, System.EventArgs e )


{
Encryption.MainForm.SetBitStrength( Convert.ToInt32( numericUpDown.Value ) );
this.DialogResult = DialogResult.OK;
this.Dispose( true );
}

privatevoid KeyPairGeneratorForm_Load( object sender, EventArgs e )


{ Encryption.MainForm.SetBitStrength( 1024 ); }
}

62
}

63

You might also like