Encrypt() public static method

public static Encrypt ( string plainText, string password, string salt = "Kosher", string hashAlgorithm = "SHA1", int passwordIterations = 2, string initialVector = "OFRna73m*aze01xY", int keySize = 256 ) : string
plainText string
password string
salt string
hashAlgorithm string
passwordIterations int
initialVector string
keySize int
return string
コード例 #1
0
ファイル: MainForm.cs プロジェクト: h5p9sl/Crypto-Notepad
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int    saveCaret      = customRTB.SelectionStart;
            string NameWithotPath = Path.GetFileName(OpenFile.FileName);

            SaveFile.FileName = currentFilename;
            EnterKeyForm f2 = new EnterKeyForm();

            if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
            {
                f2.ShowDialog();
                if (PublicVar.okPressed == false)
                {
                    return;
                }
                PublicVar.okPressed = false;
            }

            if (SaveFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (TypedPassword.Value == null)
            {
                TypedPassword.Value = PublicVar.encryptionKey.Get();
            }

            filePath = SaveFile.FileName;
            string noenc = customRTB.Text;
            string en;

            en             = AES.Encrypt(customRTB.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
            customRTB.Text = en;
            StreamWriter sw = new StreamWriter(filePath);
            int          i  = customRTB.Lines.Count();
            int          j  = 0;

            i = i - 1;
            while (j <= i)
            {
                sw.WriteLine(customRTB.Lines.GetValue(j).ToString());
                j = j + 1;
            }
            sw.Close();
            customRTB.Text = noenc;
            this.Text      = appName + Path.GetFileName(filePath);
            customRTB.Select(Convert.ToInt32(saveCaret), 0);
            PublicVar.encryptionKey.Set(TypedPassword.Value);
            TypedPassword.Value = null;
            currentFilename     = Path.GetFileName(SaveFile.FileName);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ethanliew/Crypto-Notepad
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string NameWithotPath = Path.GetFileName(OpenFile.FileName);

            if (string.IsNullOrEmpty(publicVar.encryptionKey))
            {
                Form2 Form2 = new Form2();
                Form2.ShowDialog();
                if (publicVar.okPressed == false)
                {
                    return;
                }
                publicVar.okPressed = false;
            }

            if (SaveFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            filename = SaveFile.FileName;

            string noenc = customRTB.Text;
            string en    = AES.Encrypt(customRTB.Text, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);

            customRTB.Text = en;
            StreamWriter sw = new StreamWriter(filename);
            int          i  = customRTB.Lines.Count();
            int          j  = 0;

            i = i - 1;
            while (j <= i)
            {
                sw.WriteLine(customRTB.Lines.GetValue(j).ToString());
                j = j + 1;
            }
            sw.Close();
            customRTB.Text = noenc;
            string cc = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);

            customRTB.Select(Convert.ToInt32(cc), 0);
            this.Text = appName + Path.GetFileName(filename);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: ethanliew/Crypto-Notepad
        private void saveToolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            string noname         = "Unnamed.cnp";
            string NameWithotPath = Path.GetFileName(OpenFile.FileName);

            if (filename == noname)
            {
                SaveFile.FileName = noname;
                saveAsToolStripMenuItem_Click(this, new EventArgs());

                if (publicVar.okPressed == false)
                {
                    return;
                }

                publicVar.okPressed = false;
            }

            string noenc = customRTB.Text;
            string en    = AES.Encrypt(customRTB.Text, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);

            customRTB.Text = en;
            StreamWriter sw = new StreamWriter(filename);
            int          i  = customRTB.Lines.Count();
            int          j  = 0;

            i = i - 1;

            while (j <= i)
            {
                sw.WriteLine(customRTB.Lines.GetValue(j).ToString());
                j = j + 1;
            }

            sw.Close();
            customRTB.Text = noenc;
            string cc = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);

            customRTB.Select(Convert.ToInt32(cc), 0);
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: h5p9sl/Crypto-Notepad
        private void saveToolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            int saveCaret = customRTB.SelectionStart;

            if (PublicVar.encryptionKey.Get() == null)
            {
                SaveFile.FileName = "Unnamed.cnp";
                saveAsToolStripMenuItem_Click(sender, e);
                if (PublicVar.okPressed == false)
                {
                    return;
                }
                PublicVar.okPressed = false;
            }

            string noenc = customRTB.Text;
            string en;

            en             = AES.Encrypt(customRTB.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
            customRTB.Text = en;

            StreamWriter sw = new StreamWriter(filePath);
            int          i  = customRTB.Lines.Count();
            int          j  = 0;

            i = i - 1;

            while (j <= i)
            {
                sw.WriteLine(customRTB.Lines.GetValue(j).ToString());
                j = j + 1;
            }
            sw.Close();

            customRTB.Text = noenc;
            customRTB.Select(Convert.ToInt32(saveCaret), 0);
            PublicVar.keyChanged = false;
            //CheckFileSavedCorrectly(sender, e);
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: h5p9sl/Crypto-Notepad
        public void ContextMenuEncryptReplace()
        {
            PublicVar.openFileName = Path.GetFileName(args[1]);
            DialogResult res = new DialogResult();

            if (args[1].Contains(".cnp"))
            {
                MessageBox.Show("Looks like this file is already encrypted", "Crypto Notepad", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            res = MessageBox.Show("This action will delete the source file and replace it with encrypted version", "Crypto Notepad", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (res == DialogResult.Cancel)
            {
                Environment.Exit(0);
            }

            if (!args[1].Contains(".cnp"))
            {
                string opnfile = File.ReadAllText(args[1]);
                customRTB.Text = opnfile;
                string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.Select(Convert.ToInt32(cc2), 0);
                currentFilename = Path.GetFileName(args[1]);
                string newFile = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp";

                EnterKeyForm f2 = new EnterKeyForm();
                f2.ShowDialog();
                if (PublicVar.okPressed == false)
                {
                    Application.Exit();
                }
                PublicVar.okPressed = false;

                File.Delete(args[1]);

                string noenc = customRTB.Text;
                string en;
                en             = AES.Encrypt(customRTB.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
                customRTB.Text = en;
                StreamWriter sw = new StreamWriter(newFile);
                int          i  = customRTB.Lines.Count();
                int          j  = 0;
                i = i - 1;
                while (j <= i)
                {
                    sw.WriteLine(customRTB.Lines.GetValue(j).ToString());
                    j = j + 1;
                }
                sw.Close();
                PublicVar.encryptionKey.Set(TypedPassword.Value);
                TypedPassword.Value = null;
                filePath            = newFile;
                currentFilename     = Path.GetFileName(newFile);
                this.Text           = appName + currentFilename;
                customRTB.Text      = noenc;
            }

            #region workaround, strange behavior with the cursor in customRTB fix
            customRTB.DetectUrls = false;
            customRTB.DetectUrls = true;
            customRTB.Modified   = false;
            #endregion

            if (PublicVar.okPressed == true)
            {
                PublicVar.okPressed = false;
            }
        }