Example #1
0
        public static Configuration LoadFile(string filename)
        {
            Configuration config;

            try
            {
                if (File.Exists(filename))
                {
                    var configContent = File.ReadAllText(filename);
                    config = Load(configContent);
                    if (config != null)
                    {
                        return(config);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            config = new Configuration();
            config.FixConfiguration();
            return(config);
        }
Example #2
0
 public static Configuration Load(string config_str)
 {
     try
     {
         if (GlobalConfiguration.config_password.Length > 0)
         {
             byte[]     cfg_encrypt = System.Convert.FromBase64String(config_str);
             IEncryptor encryptor   = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password);
             byte[]     cfg_data    = new byte[cfg_encrypt.Length];
             int        data_len;
             encryptor.Decrypt(cfg_encrypt, cfg_encrypt.Length, cfg_data, out data_len);
             config_str = UTF8Encoding.UTF8.GetString(cfg_data, 0, data_len);
         }
     }
     catch
     {
     }
     try
     {
         Configuration config = SimpleJson.SimpleJson.DeserializeObject <Configuration>(config_str, new JsonSerializerStrategy());
         config.FixConfiguration();
         return(config);
     }
     catch
     {
     }
     return(null);
 }
Example #3
0
 public static Configuration Load(string config_str)
 {
     try
     {
         if (GlobalConfiguration.config_password.Length > 0)
         {
             byte[]     cfg_encrypt = System.Convert.FromBase64String(config_str);
             IEncryptor encryptor   = EncryptorFactory.GetEncryptor("aes-256-cfb", GlobalConfiguration.config_password, false);
             byte[]     cfg_data    = new byte[cfg_encrypt.Length];
             int        data_len    = 0;
             const int  buffer_size = 32768;
             byte[]     input       = new byte[buffer_size];
             byte[]     ouput       = new byte[buffer_size + 128];
             for (int start_pos = 0; start_pos < cfg_encrypt.Length; start_pos += buffer_size)
             {
                 int len = Math.Min(cfg_encrypt.Length - start_pos, buffer_size);
                 int out_len;
                 Buffer.BlockCopy(cfg_encrypt, start_pos, input, 0, len);
                 encryptor.Decrypt(input, len, ouput, out out_len);
                 Buffer.BlockCopy(ouput, 0, cfg_data, data_len, out_len);
                 data_len += out_len;
             }
             config_str = UTF8Encoding.UTF8.GetString(cfg_data, 0, data_len);
         }
     }
     catch
     {
     }
     try
     {
         Configuration config = SimpleJson.SimpleJson.DeserializeObject <Configuration>(config_str, new JsonSerializerStrategy());
         config.FixConfiguration();
         return(config);
     }
     catch
     {
     }
     return(null);
 }