Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Editer
            string date = calendrier.SelectionRange.Start.ToString("yyyy-MM-dd");

            richTextBox1.Text = String.Empty;

            if (File.Exists(adresseDossier + date))
            {
                string      buffer      = File.ReadAllText(adresseDossier + date);
                string[]    buffToPlain = buffer.Split(' ');
                List <byte> toPlain     = new List <byte>();
                foreach (string s in buffToPlain)
                {
                    if (!String.IsNullOrEmpty(s))
                    {
                        toPlain.Add(byte.Parse(s));
                    }
                }

                byte[] toUncipher = toPlain.ToArray();

                string result = String.Empty;
                if (null != CipherTools.Decrypt(toUncipher, pwd, salt))
                {
                    result = Encoding.Unicode.GetString(CipherTools.Decrypt(toUncipher, pwd, salt));
                }
                else
                {
                    result = "Il semblerait qu'il faille utiliser le bon mot de passe ;)";
                }

                richTextBox1.Text = result;
            }
        }
Exemple #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            //Enregistrer les modifs
            string date = calendrier.SelectionRange.Start.ToString("yyyy-MM-dd");

            if (File.Exists(adresseDossier + date))
            {
                //File.WriteAllText(adresseDossier + date, richTextBox1.Text);
                byte[] cipher = CipherTools.Encrypt(Encoding.Unicode.GetBytes(richTextBox1.Text), pwd, salt);
                string result = String.Empty;
                foreach (byte c in cipher)
                {
                    result += c.ToString() + " ";
                }
                File.WriteAllText(adresseDossier + date, result);
            }
        }
Exemple #3
0
        private void buttonUnlock_Click(object sender, EventArgs e)
        {
            //Déverrouiller
            if (String.IsNullOrEmpty(textPassword.Text))
            {
                File.AppendAllText(@"test.txt", "data");
                return;
            }

            string password = textPassword.Text;

            byte[] salty = Encoding.Unicode.GetBytes(password);

            string buffer = File.ReadAllText(adresseDossier + @"\keycipher");

            string[]    buffToPlain = buffer.Split(' ');
            List <byte> toPlain     = new List <byte>();

            foreach (string s in buffToPlain)
            {
                if (!String.IsNullOrEmpty(s))
                {
                    toPlain.Add(byte.Parse(s));
                }
            }

            byte[] toUncipher = toPlain.ToArray();

            string result = String.Empty;

            if (null != CipherTools.Decrypt(toUncipher, password, salty))
            {
                pwd  = Encoding.Unicode.GetString(CipherTools.Decrypt(toUncipher, password, salty));
                salt = Encoding.Unicode.GetBytes(pwd);
            }
            else
            {
                richTextBox1.Text = "Il semblerait qu'il faille utiliser le bon mot de passe ;)";
            }

            //richTextBox1.Text = result;
            //CipherTools.GenerateKey(@"d:\LocalData\i021473\Desktop\Calendrier\key", password, salty);
        }
Exemple #4
0
        private void buttonNouveau_Click(object sender, EventArgs e)
        {
            //Creer
            string date = calendrier.SelectionRange.Start.ToString("yyyy-MM-dd");

            if (!String.IsNullOrEmpty(pwd))
            {
                if (!File.Exists(adresseDossier + date))
                {
                    File.Create(adresseDossier + date).Close();
                    if (richTextBox1.Text.Length > 0)
                    {
                        //File.AppendAllText(adresseDossier + date, richTextBox1.Text);
                        byte[] cipher = CipherTools.Encrypt(Encoding.Unicode.GetBytes(richTextBox1.Text), pwd, salt);
                        string result = String.Empty;
                        foreach (byte c in cipher)
                        {
                            result += c.ToString() + " ";
                        }
                        File.AppendAllText(adresseDossier + date, result);
                    }
                }
            }
        }