Exemple #1
0
        void LoadSettings()
        {
            using (var file = File.OpenText(SETTINGS_FILE))
                using (var reader = new JsonTextReader(file))
                {
                    var o2 = (JObject)JToken.ReadFrom(reader);
                    ENCRYPTION_SALT = (string)o2["encryption_settings"]["salt"];
                    if (((string)o2["ftp_settings"]["url"]).Length != 0)
                    {
                        FTP_URL = EncryptDecryptUtils.Decrypt((string)o2["ftp_settings"]["url"], SETTINGS_FILE, ENCRYPTION_SALT, "SHA1");
                    }
                    if (((string)o2["ftp_settings"]["username"]).Length != 0)
                    {
                        FTP_USERNAME = EncryptDecryptUtils.Decrypt((string)o2["ftp_settings"]["username"], SETTINGS_FILE, ENCRYPTION_SALT, "SHA1");
                    }
                    if (((string)o2["ftp_settings"]["password"]).Length != 0)
                    {
                        FTP_PASSWORD = EncryptDecryptUtils.Decrypt((string)o2["ftp_settings"]["password"], SETTINGS_FILE, ENCRYPTION_SALT, "SHA1");
                    }

                    FTPUrl.Text         = FTP_URL;
                    FTPUsername.Text    = FTP_USERNAME;
                    FTPPassword.Text    = FTP_PASSWORD;
                    EncryptionSalt.Text = ENCRYPTION_SALT;
                }
            _form1.SETTINGS_LOADED = true;
        }
Exemple #2
0
        void CreateFile()
        {
            var settings_file = new JObject {
                { "ftp_settings", new JObject {
                      { "url", EncryptDecryptUtils.Encrypt(FTP_URL, SETTINGS_FILE, ENCRYPTION_SALT, "SHA1") },
                      { "username", EncryptDecryptUtils.Encrypt(FTP_USERNAME, SETTINGS_FILE, ENCRYPTION_SALT, "SHA1") },
                      { "password", EncryptDecryptUtils.Encrypt(FTP_PASSWORD, SETTINGS_FILE, ENCRYPTION_SALT, "SHA1") }
                  } },
                { "encryption_settings", new JObject {
                      { "salt", ENCRYPTION_SALT }
                  } }
            };

            File.WriteAllText(SETTINGS_FILE, settings_file.ToString());

            using (var file = File.CreateText(SETTINGS_FILE))
                using (var writer = new JsonTextWriter(file))
                {
                    settings_file.WriteTo(writer);
                    _form1.Log("Saved settings file: savefilesync.dat.");
                }
        }