Decrypt() public static method

public static Decrypt ( string cipherText, string password, string salt = "Kosher", string hashAlgorithm = "SHA1", int passwordIterations = 2, string initialVector = "OFRna73m*aze01xY", int keySize = 256 ) : string
cipherText string
password string
salt string
hashAlgorithm string
passwordIterations int
initialVector string
keySize int
return string
Ejemplo n.º 1
0
        void AutoLock(bool minimize)
        {
            saveToolStripMenuItem1_Click_1(this, new EventArgs());
            Form2 f2 = new Form2();

            publicVar.encryptionKey = "";
            caretPos       = customRTB.SelectionStart;
            f2.MinimizeBox = true;
            this.Hide();

            if (minimize == true)
            {
                f2.WindowState = FormWindowState.Minimized;
            }
            f2.ShowDialog();

            if (publicVar.okPressed == false)
            {
                publicVar.encryptionKey = "";
                customRTB.Clear();
                this.Text         = appName.Remove(14);
                OpenFile.FileName = "";
                this.Show();
                return;
            }
            publicVar.okPressed = false;

            try
            {
                OpenFile.FileName = filename;
                string opnfile        = File.ReadAllText(OpenFile.FileName);
                string NameWithotPath = Path.GetFileName(OpenFile.FileName);
                string de             = AES.Decrypt(opnfile, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);

                this.Text = appName + NameWithotPath;
                filename  = OpenFile.FileName;

                string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.SelectionStart = caretPos;
                this.Show();
            }
            catch (CryptographicException)
            {
                DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                if (dialogResult == DialogResult.Retry)
                {
                    AutoLock(false);
                }
                if (dialogResult == DialogResult.Cancel)
                {
                    publicVar.encryptionKey = "";
                    customRTB.Clear();
                    this.Text         = appName.Remove(14);
                    OpenFile.FileName = "";
                    this.Show();
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void openAsotiations()
        {
            EnterKeyForm Form2 = new EnterKeyForm();

            Form2.StartPosition = FormStartPosition.CenterScreen;
            string fileExtension = Path.GetExtension(args[1]);

            if (fileExtension == ".cnp")
            {
                try
                {
                    string NameWithotPath = Path.GetFileName(args[1]);
                    string opnfile        = File.ReadAllText(args[1]);

                    Form2.ShowDialog();
                    if (PublicVar.okPressed == false)
                    {
                        OpenFile.FileName = "";
                        return;
                    }
                    PublicVar.okPressed = false;

                    string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
                    customRTB.Text = de;

                    this.Text = appName + NameWithotPath;

                    filePath = args[1];
                    string cc = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                    PublicVar.encryptionKey.Set(TypedPassword.Value);
                    customRTB.Select(Convert.ToInt32(cc), 0);
                    TypedPassword.Value = null;
                }
                catch (CryptographicException)
                {
                    TypedPassword.Value = null;
                    DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (dialogResult == DialogResult.Retry)
                    {
                        openAsotiations();
                    }
                }
            }
            else
            {
                string opnfile        = File.ReadAllText(args[1]);
                string NameWithotPath = Path.GetFileName(args[1]);
                customRTB.Text = opnfile;
                this.Text      = appName + NameWithotPath;
                string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.Select(Convert.ToInt32(cc2), 0);
            }

            currentFilename = Path.GetFileName(args[1]);
        }
Ejemplo n.º 3
0
        void DecryptAES()
        {
            EnterKeyForm f2 = new EnterKeyForm();

            f2.ShowDialog();
            if (PublicVar.okPressed == false)
            {
                return;
            }
            if (panel1.Visible == true)
            {
                findToolStripMenuItem2_Click(this, new EventArgs());
            }
            try
            {
                string opnfile        = File.ReadAllText(OpenFile.FileName);
                string NameWithotPath = Path.GetFileName(OpenFile.FileName);

                string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
                customRTB.Text = de;

                this.Text = appName + NameWithotPath;
                filePath  = OpenFile.FileName;
                string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.Select(Convert.ToInt32(cc2), 0);

                PublicVar.openFileName = Path.GetFileName(OpenFile.FileName);
                currentFilename        = Path.GetFileName(OpenFile.FileName);
                PublicVar.encryptionKey.Set(TypedPassword.Value);
                TypedPassword.Value = null;
            }
            catch (CryptographicException)
            {
                using (new CenterWinDialog(this))
                {
                    TypedPassword.Value = null;
                    DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (dialogResult == DialogResult.Retry)
                    {
                        DecryptAES();
                    }
                    if (dialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void openAsotiations()
        {
            Form2 Form2 = new Form2();

            Form2.StartPosition = FormStartPosition.CenterScreen;

            try
            {
                string NameWithotPath = Path.GetFileName(args[1]);
                string opnfile        = File.ReadAllText(args[1]);

                Form2.ShowDialog();
                if (publicVar.okPressed == false)
                {
                    OpenFile.FileName = "";
                    return;
                }
                publicVar.okPressed = false;

                string de = AES.Decrypt(opnfile, publicVar.encryptionKey, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, "16CHARSLONG12345", ps.KeySize);
                customRTB.Text = de;

                this.Text = appName + NameWithotPath;

                filename = args[1];
                string cc = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.Select(Convert.ToInt32(cc), 0);
            }

            catch
            {
                DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                if (dialogResult == DialogResult.Retry)
                {
                    openAsotiations();
                }
            }
            currentFilename = Path.GetFileName(OpenFile.FileName);
        }
Ejemplo n.º 5
0
        void AutoLock(bool minimize)
        {
            EnterKeyForm f2 = new EnterKeyForm();

            PublicVar.encryptionKey.Set(null);
            caretPos       = customRTB.SelectionStart;
            f2.MinimizeBox = true;
            this.Hide();

            if (minimize == true)
            {
                f2.WindowState = FormWindowState.Minimized;
            }
            f2.ShowDialog();

            if (PublicVar.okPressed == false)
            {
                PublicVar.encryptionKey.Set(null);
                customRTB.Clear();
                this.Text       = appName.Remove(14);
                currentFilename = "";
                filePath        = "";
                this.Show();
                return;
            }
            PublicVar.okPressed = false;

            try
            {
                customRTB.Clear();
                string opnfile = File.ReadAllText(filePath);
                string de      = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
                customRTB.Text = de;
                this.Text      = appName + currentFilename;
                string cc2 = customRTB.Text.Length.ToString(CultureInfo.InvariantCulture);
                customRTB.Select(Convert.ToInt32(cc2), 0);
                customRTB.SelectionStart = caretPos;
                PublicVar.encryptionKey.Set(TypedPassword.Value);
                TypedPassword.Value = null;
                this.Show();
            }
            catch (Exception ex)
            {
                if (ex is CryptographicException)
                {
                    TypedPassword.Value = null;
                    DialogResult dialogResult = MessageBox.Show("Invalid key!", "Crypto Notepad", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (dialogResult == DialogResult.Retry)
                    {
                        AutoLock(false);
                    }
                    if (dialogResult == DialogResult.Cancel)
                    {
                        PublicVar.encryptionKey.Set(null);
                        customRTB.Clear();
                        this.Text       = appName.Remove(14);
                        filePath        = "";
                        currentFilename = "";
                        this.Show();
                        return;
                    }
                }
            }
        }