Пример #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;
            }
        }
Пример #2
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);
        }