/// <summary>
        /// Saves Crm connections list to file
        /// </summary>
        public void SaveConnectionsFile()
        {
            if (!string.IsNullOrEmpty(ConnectionsList.Password))
            {
                ConnectionsList.Password = CryptoManager.Encrypt(ConnectionsList.Password,
                                                                 CryptoPassPhrase,
                                                                 CryptoSaltValue,
                                                                 CryptoHashAlgorythm,
                                                                 CryptoPasswordIterations,
                                                                 CryptoInitVector,
                                                                 CryptoKeySize);
            }

            ConnectionsList.SerializeToFile(ConfigurationFile);
        }
 public void SetPassword(string password, bool isEncrypted = false)
 {
     if (!string.IsNullOrEmpty(password))
     {
         if (isEncrypted)
         {
             userPassword = password;
         }
         else
         {
             userPassword = CryptoManager.Encrypt(password, ConnectionManager.CryptoPassPhrase,
                                                  ConnectionManager.CryptoSaltValue,
                                                  ConnectionManager.CryptoHashAlgorythm,
                                                  ConnectionManager.CryptoPasswordIterations,
                                                  ConnectionManager.CryptoInitVector,
                                                  ConnectionManager.CryptoKeySize);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Saves Crm connections list to file
        /// </summary>
        public void SaveConnectionsFile(CrmConnections connectionsList)
        {
            if (!string.IsNullOrEmpty(connectionsList.Password))
            {
                connectionsList.Password = CryptoManager.Encrypt(connectionsList.Password,
                                                                 CryptoPassPhrase,
                                                                 CryptoSaltValue,
                                                                 CryptoHashAlgorythm,
                                                                 CryptoPasswordIterations,
                                                                 CryptoInitVector,
                                                                 CryptoKeySize);
            }

            var cache = new Dictionary <Guid, string>();

            lock (connectionsList.Connections)
            {
                foreach (var detail in connectionsList.Connections)
                {
                    if (!detail.ConnectionId.HasValue)
                    {
                        continue;
                    }

                    cache.Add(detail.ConnectionId.Value, detail.UserPassword);

                    if (detail.SavePassword)
                    {
                        if (!string.IsNullOrEmpty(detail.UserPassword))
                        {
                            detail.UserPassword = CryptoManager.Encrypt(detail.UserPassword,
                                                                        CryptoPassPhrase,
                                                                        CryptoSaltValue,
                                                                        CryptoHashAlgorythm,
                                                                        CryptoPasswordIterations,
                                                                        CryptoInitVector,
                                                                        CryptoKeySize);
                        }
                    }
                    else
                    {
                        detail.UserPassword = null;
                    }
                }

                XmlSerializerHelper.SerializeToFile(connectionsList, ConfigFileName);

                foreach (var detail in connectionsList.Connections)
                {
                    if (!detail.ConnectionId.HasValue)
                    {
                        continue;
                    }

                    if (detail.UserPassword == null)
                    {
                        detail.UserPassword = cache[detail.ConnectionId.Value];
                        continue;
                    }

                    if (!string.IsNullOrEmpty(detail.UserPassword))
                    {
                        detail.UserPassword = CryptoManager.Decrypt(detail.UserPassword,
                                                                    CryptoPassPhrase,
                                                                    CryptoSaltValue,
                                                                    CryptoHashAlgorythm,
                                                                    CryptoPasswordIterations,
                                                                    CryptoInitVector,
                                                                    CryptoKeySize);
                    }
                }
            }
        }