Open source Email App

Email Encryption Application: Open Source

If you are interested in having a copy of it, let me know. I dread putting it on Sourceforge, due to rampant misuse, of open source software. 

 

Encryption Panel:

 

Decryption panel

 

Encryption Code Coutesy: http://www.codeproject.com/KB/security/fileencryptdecrypt.aspx

/*******************************************************************
     * This code is a reuse of code that can be found on C# opensource.
     * The changes are in implementation, pass strings for the encrypted
     * text and passphrase in another class. Object oreinted approach to
     * an application for encrypted emails.
     * Author: Nathan Blomquist, purpose: code reuse.
     * http://www.codeproject.com/KB/security/fileencryptdecrypt.aspx
     *******************************************************************/
    class Class1
    {
        public static byte[] Encrypt(byte[] clearData, byte[] Key, byte[] IV)
        {
            MemoryStream ms = new MemoryStream();
            Rijndael alg = Rijndael.Create();   
            alg.Key = Key;
            alg.IV = IV;
           
            CryptoStream cs = new CryptoStream(ms,
               alg.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(clearData, 0, clearData.Length);
            cs.Close();

            byte[] encryptedData = ms.ToArray();

            return encryptedData;
        }

        public string Encrypt(string clearText, string Password)
        {
            byte[] clearBytes =
              System.Text.Encoding.Unicode.GetBytes(clearText);

            PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
                new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
            0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

            byte[] encryptedData = Encrypt(clearBytes,
                     pdb.GetBytes(32), pdb.GetBytes(16));

            return Convert.ToBase64String(encryptedData);
        }

        public static byte[] Decrypt(byte[] cipherData,
                                byte[] Key, byte[] IV)
        {
            MemoryStream ms = new MemoryStream();
            Rijndael alg = Rijndael.Create();
            alg.Key = Key;
            alg.IV = IV;

            CryptoStream cs = new CryptoStream(ms,
                alg.CreateDecryptor(), CryptoStreamMode.Write);
            cs.Write(cipherData, 0, cipherData.Length);
            cs.Close();

            byte[] decryptedData = ms.ToArray();

            return decryptedData;
        }

        public string Decrypt(string cipherText, string Password)
        {

            byte[] cipherBytes = Convert.FromBase64String(cipherText);

            PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password,
                new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65,
            0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

            byte[] decryptedData = Decrypt(cipherBytes,
                pdb.GetBytes(32), pdb.GetBytes(16));

            return System.Text.Encoding.Unicode.GetString(decryptedData);
        }
    }

 

Email Code:

 MailMessage mess = new MailMessage();

        public void useMail(string password, string emailAddrress, string body, string reciever, string SMTP)
        {
            mess.From = new MailAddress(emailAddrress);                         //from email   
            mess.To.Add(reciever);                                              //to email
            mess.Subject = "Message For you.";                                  //subject
            mess.Body = body;                                                   //body
            SmtpClient smtp = new SmtpClient(SMTP);                             //client
            smtp.Credentials = new NetworkCredential(emailAddrress, password);  //credentials for SMTP use
            smtp.EnableSsl = true;                                              //SSL Enabled
            smtp.Send(mess);                                                    //Send the message
        }

 

Form Infrastructure Code

 

public partial class Form1 : Form
    {
        Class1 secClass = new Class1();
        Class2 emailClass = new Class2();

        public Form1()
        {
            InitializeComponent();
        }

        //Button Method to encrypt.
        private void button1_Click(object sender, EventArgs e)
        {
            if (passphrase.Text != "" && passphrase.Text != null)
            {
                if (passphrase.Text == passphrase_confirm.Text)
                {//Test the phrases to see if they are the same, if they are run the encryption
                    this.encryptedBody.Text = secClass.Encrypt(this.BodyCreate.Text, this.passphrase.Text);
                }
                else
                {//catch error
                    this.BackColor = Color.Red;
                    MessageBox.Show("The passphrases do not match. Check them to be sure they match.");
                    this.BackColor = Color.SteelBlue;
                }
            }
            else
            {//catch empty box
                this.BackColor = Color.Red;
                MessageBox.Show("If the Passphrase is left empty then the encryption is weak, please enter a strong passphrase.");
                this.BackColor = Color.SteelBlue;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {//Try to send the email
                if (sender_email.Text != "" && sender_email_password.Text != "" && sender_smtp.Text != "" && encryptedBody.Text != "" && reciever_email_address.Text != "")
                {//Test the text boxes to see if they are empty
                    {//send the email and switch to decoding for incomming message
                        emailClass.useMail(this.sender_email_password.Text, this.sender_email.Text, encryptedBody.Text, reciever_email_address.Text, this.sender_smtp.Text);
                        panel1.Visible = false;
                        panel2.Visible = true;
                    }
                }
                else
                {//catch empty fields
                    MessageBox.Show("There are parts of the form that are not complete Please complete them.");
                }
            }
            catch (Exception f)
            {//catch exception to email sending method
                MessageBox.Show(f.Message.ToString() + "\nCheck the Email addresses, make sure that they are valid.");
            }
        }
        //decrypt
        private void button3_Click(object sender, EventArgs e)
        {
            //this.BackColor = Color.SteelBlue;
            try
            {
                int count = 0;
                if (count <= 5)
                {//Test to see how many times the user has tried to use a bad passphrase
                    //if (this.passphrase.Text == this.deycrypt_passphrase.Text)
                    //{//decrypt, make sure passphrases are correct
                    this.richTextBox2.Text = secClass.Decrypt(richTextBox1.Text, deycrypt_passphrase.Text);
                    // }
                    //else
                    //{//Passphrase fail message

                    //}
                }
                else
                {//user fails to use the right passphrase, exit the application.
                    this.BackColor = Color.DarkMagenta;
                    Application.Exit();
                }
            }
            catch
            {//catch empty fields
                this.BackColor = Color.Red;
                MessageBox.Show("One or more of the fields is Empty, or the passphrase is incorrect");
                this.BackColor = Color.SteelBlue;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //return to encryption send page
            panel2.Visible = false;
            panel1.Visible = true;
        }

        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {//Go to help file
           
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {//go to decoding page
            panel2.Visible = true;
            panel1.Visible = false;
        }

        private void encodeToolStripMenuItem_Click(object sender, EventArgs e)
        {//go to encoding page
            panel2.Visible = false;
            panel1.Visible = true;
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void openHelpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.Start("helpFile.htm");
        }

    }

 

 

Load Comments...

Send this Article to a Friend



Separate multiple emails with a comma (,); limit 5 recipients






Your email has been sent successfully!

Manage this Video in Your Playlists

New Blog Posts from All Members