/// <summary>
        /// Delete a specify connection
        /// </summary>
        /// <param name="tmpConnectionToSet">connection to delete</param>
        internal void DeleteConnection(ConnectionModel tmpConnectionToSet)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            string encComputerMacAddress = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineMacAddress, Pepper), Key256Bits);
            string encComputerName       = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineName, Pepper), Key256Bits);
            string encComputerUserName   = engine.Encrypt(string.Concat(Salt, tmpConnectionToSet.MachineUserName, Pepper), Key256Bits);

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                // Delete any previous row which match
                List <ConnectionTemp> existingConnections = (from conn in context.ConnectionTemps
                                                             where conn.ComputerMacAddress.Equals(encComputerMacAddress) &&
                                                             conn.ComputerName.Equals(encComputerName) &&
                                                             conn.ComputerUserName.Equals(encComputerUserName)
                                                             select conn).ToList();

                if (existingConnections.Count > 0)
                {
                    context.ConnectionTemps.RemoveRange(existingConnections);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        internal static string AESEncryption(string plain, string key, string salt, Pkcs7Padding padding)
        {
            BCEngine bcEngine = new BCEngine(new AesEngine(), Encoding.UTF8);

            bcEngine.SetPadding(padding);
            return(bcEngine.Encrypt(plain, key));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update a password
        /// </summary>
        /// <param name="pwdToUpdate">Password to update</param>
        internal void Update(PasswordModel pwdToUpdate)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                Password pass = GetPassword(context, pwdToUpdate.Id);

                pass.DisplayName = pwdToUpdate.DisplayName;
                pass.Login       = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Login, Pepper), Key256Bits);
                pass.Password1   = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Password, Pepper), Key256Bits);
                pass.Url         = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Url, Pepper), Key256Bits);
                pass.Notes       = engine.Encrypt(string.Concat(Salt, pwdToUpdate.Notes, Pepper), Key256Bits);

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Get the last user id for the given connection details
        /// </summary>
        /// <param name="tmpConnection">Connection data</param>
        /// <returns>The user id</returns>
        internal int?GetConnectionTempUserId(ConnectionModel tmpConnection)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            string encComputerMacAddress = engine.Encrypt(string.Concat(Salt, tmpConnection.MachineMacAddress, Pepper), Key256Bits);
            string encComputerName       = engine.Encrypt(string.Concat(Salt, tmpConnection.MachineName, Pepper), Key256Bits);
            string encComputerUserName   = engine.Encrypt(string.Concat(Salt, tmpConnection.MachineUserName, Pepper), Key256Bits);

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                int usrIdLogin = (from conn in context.ConnectionTemps
                                  where conn.ComputerMacAddress.Equals(encComputerMacAddress) &&
                                  conn.ComputerName.Equals(encComputerName) &&
                                  conn.ComputerUserName.Equals(encComputerUserName)
                                  select conn.IdUser).FirstOrDefault();

                return(usrIdLogin == 0 ? new int?() : usrIdLogin);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a new password
        /// </summary>
        /// <param name="pwdToCreate">Password to create</param>
        internal void Create(PasswordModel pwdToCreate)
        {
            BCEngine engine = new BCEngine(new AesEngine(), Encoding.UTF8);

            engine.SetPadding(new Pkcs7Padding());

            using (PasswordKeeperEntities context = new PasswordKeeperEntities())
            {
                Password newPwd = new Password()
                {
                    Login        = engine.Encrypt(string.Concat(Salt, pwdToCreate.Login, Pepper), Key256Bits),
                    Password1    = engine.Encrypt(string.Concat(Salt, pwdToCreate.Password, Pepper), Key256Bits),
                    DisplayName  = pwdToCreate.DisplayName,
                    Url          = engine.Encrypt(string.Concat(Salt, pwdToCreate.Url, Pepper), Key256Bits),
                    Notes        = engine.Encrypt(string.Concat(Salt, pwdToCreate.Notes, Pepper), Key256Bits),
                    CreationDate = pwdToCreate.CreationDate,
                    IsActive     = pwdToCreate.IsActive,
                    UserId       = pwdToCreate.UserId
                };

                context.Passwords.Add(newPwd);
                context.SaveChanges();
            }
        }