示例#1
0
        private void MenuHelp_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Started MenuHelp_Click(...)");
            //Console.WriteLine(this.data.ToString());

            Cryptographer c    = new Cryptographer(PasswordStorage.TEMP_TEST_MASTERKEY);
            string        encr = "Test!?tseT";

            Console.WriteLine($"{encr} => {c.Encrypt(encr)} => {c.Decrypt(c.Encrypt(encr))}");

            string pp = "ppas|" + encr + "|ollse213";

            Console.WriteLine($"RemoveSubString(...) = {PasswordStorage.RemoveSubString(pp, encr)}");



            Console.WriteLine("Ended   MenuHelp_Click(...)");
        }
示例#2
0
        public void Serialize(string FilePathAndName)
        {
            bool retry = false;

            byte[] xml_bytes;
            do
            {
                retry = false;
                try
                {
                    using (FileStream file = new FileStream(FilePathAndName, FileMode.Create))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            this.data.WriteXml(ms);
                            xml_bytes = ms.ToArray();
                        }

                        Cryptographer c = new Cryptographer(TEMP_TEST_MASTERKEY);
                        string        encrypted_data = c.Encrypt(xml_bytes);

                        using (StreamWriter sw = new StreamWriter(file))
                        {
                            var x = Encoding.UTF8.GetString(c.MasterKeyHash);
                            sw.WriteLine(x);
                            sw.WriteLine(encrypted_data);
                        }
                    }
                }
                catch (Exception)
                {
                    var response = MessageBox.Show("An error occured during writing the file", "Couldn't write file", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    retry = (response == DialogResult.Retry);
                }
            } while (retry);
        }