コード例 #1
0
ファイル: LoadVaultForm.cs プロジェクト: Scopola/PassSave
 private void button1_Click(object sender, EventArgs e)
 {
     if (!File.Exists(valutFile))
     {
         MessageBox.Show("Vault file has been deleted!");
         Environment.Exit(0);
         return;
     }
     try
     {
         gPassword = textBox1.Text;
         byte[] VaultBytes     = File.ReadAllBytes(valutFile);
         byte[] decryptedVault = SimpleCryptography.DecryptBytes(VaultBytes, gPassword);
         using (MemoryStream ms = new MemoryStream(decryptedVault))
         {
             XDocument           xDoc   = XDocument.Load(ms);
             List <PasswordData> pwList = new List <PasswordData>();
             foreach (var el in xDoc.Descendants("vault").Descendants("dat"))
             {
                 PasswordData pwd = new PasswordData(el.Element("username").Value, el.Element("password").Value, el.Element("website").Value);
                 pwList.Add(pwd);
             }
             pwdList           = pwList.ToArray();
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
         }
     }
     catch
     {
         MessageBox.Show("Bad password.");
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: ChiruclanDE/Cessenger
        private static struct_socket sock; // socket structure with client and server socket

        #endregion Fields

        #region Methods

        private static bool init_server()
        {
            try
            {
                TextWriter tmp = Console.Out; // save old output
                Console.SetOut(TextWriter.Null); // suppress output

                config = new SimpleConfiguration("cc_server.conf");
                crypt = new SimpleCryptography();
                cache = new SimpleCaching();

                Console.SetOut(tmp); // reenable console output

                cfg.logging.file.basename = config.GetKey("logging.file.basename");
                cfg.logging.file.prefix = config.GetKey("logging.file.prefix");
                cfg.logging.file.suffix = config.GetKey("logging.file.suffix");
                bool.TryParse(config.GetKey("logging.usedate"), out cfg.logging.usedate);
                logger = new Logging(cfg.logging.file.basename, cfg.logging.file.prefix, cfg.logging.file.suffix, cfg.logging.usedate);

                cfg.server.name = config.GetKey("server.name");
                uint.TryParse(config.GetKey("server.connection.limit"), out cfg.server.connection.limit);

                cfg.inet.address = config.GetKey("inet.address");
                ushort.TryParse(config.GetKey("inet.port"), out cfg.inet.port);

                cfg.mysql.username = config.GetKey("mysql.username");
                cfg.mysql.password = config.GetKey("mysql.password");
                cfg.mysql.hostname = config.GetKey("mysql.hostname");
                cfg.mysql.database = config.GetKey("mysql.database");
                ushort.TryParse(config.GetKey("mysql.port"), out cfg.mysql.port);

                db = new Database(cfg.mysql.hostname, cfg.mysql.port, cfg.mysql.username, cfg.mysql.password, cfg.mysql.database, logger);

                sock.address = cfg.inet.address;
                sock.port = cfg.inet.port;
                sock.server = new TcpListener(sock.endpoint);

                return true;
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nError:\n{0}", ex.Message);
                return false;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Scopola/PassSave
        void Save()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (XmlTextWriter xml = new XmlTextWriter(ms, Encoding.UTF8))
                {
                    xml.WriteStartDocument();

                    xml.WriteStartElement("vault");

                    foreach (ListViewItem i in pwList.Items)
                    {
                        PasswordData pwd = (PasswordData)i.Tag;
                        xml.WriteStartElement("dat");

                        xml.WriteStartElement("username");
                        xml.WriteCData(pwd.Username);
                        xml.WriteEndElement();

                        xml.WriteStartElement("password");
                        xml.WriteCData(pwd.Password);
                        xml.WriteEndElement();

                        xml.WriteStartElement("website");
                        xml.WriteCData(pwd.Website);
                        xml.WriteEndElement();

                        xml.WriteEndElement(); //dat
                    }

                    xml.WriteEndElement(); //vault
                    xml.WriteEndDocument();
                    xml.Flush();
                    xml.Close();
                }
                byte[] saveFileEncrypted = SimpleCryptography.EncryptBytes(ms.ToArray(), globalPassword);
                File.WriteAllBytes(valutFileName, saveFileEncrypted);
            }
        }
コード例 #4
0
        public override IPersistenceConfigurer GetHibernateConfiguration()
        {
            var guestConfiguration = OracleDataClientConfiguration.Oracle10.ConnectionString(Database.ConnectionString);

            string ownerConnectionString;

            using (var sessionFactory = Fluently.Configure().Database(guestConfiguration).BuildSessionFactory())
            {
                using (var session = sessionFactory.OpenSession())
                {
                    var senhaBancoDados = session
                                          .CreateSQLQuery("SELECT PWDS_PWDDB FROM PWDS WHERE PWDS_OWNER = :owner")
                                          .AddScalar("PWDS_PWDDB", NHibernateUtil.String)
                                          .SetParameter("owner", Database.Onwer.ToUpper())
                                          .UniqueResult();

                    if (senhaBancoDados == null || string.IsNullOrEmpty(senhaBancoDados.ToString()))
                    {
                        throw new DatabaseConfigurationException(
                                  string.Format("Senha do owner {0} não foi encontrado na tabela PWDS", this.owner));
                    }

                    var password = new SimpleCryptography().Decode(senhaBancoDados.ToString());

                    ownerConnectionString = this.BuildConnectionString(new ConnectionString
                    {
                        Server   = Database.Connection.Server,
                        User     = Database.Onwer,
                        Password = password
                    });
                }
            }

            Database.RestartSettings(ownerConnectionString, Database.Onwer);
            return(OracleDataClientConfiguration.Oracle10.ConnectionString(ownerConnectionString));
        }