예제 #1
0
        private void ApplySettingsButton_Click()
        {
            byte[] pubKey         = null;
            byte[] privKey        = null;
            bool   privKeyChanged = privKeyInput.Text != PrivKeyHiddenBlurb;

            try
            {
                if (pubKeyInput.Text.Trim() != "")
                {
                    pubKey = Convert.FromBase64String(pubKeyInput.Text);
                    if (!CryptoHandler.IsKeyValid(pubKey))
                    {
                        ShowToast("Invalid Public Key");
                        return;
                    }
                }
            }
            catch (FormatException)
            {
                ShowToast("Invalid Public Key Format");
                return;
            }

            try
            {
                if (privKeyChanged && privKeyInput.Text.Trim() != "")
                {
                    privKey = Convert.FromBase64String(privKeyInput.Text);
                    if (!CryptoHandler.IsKeyValid(privKey))
                    {
                        ShowToast("Invalid Private Key");
                        return;
                    }
                }
            }
            catch (FormatException)
            {
                ShowToast("Invalid Private Key Format");
                return;
            }

            AppSettings.Global.TargetUrl = targetUrlSettingInput.Text;
            AppSettings.Global.Positions = posAvailInput.Text;
            AppSettings.Global.DeviceId  = deviceIdInput.Text;
            AppSettings.Global.GroupId   = groupIdInput.Text;
            AppSettings.Global.KioskMode = kioskModeSwitch.Checked;
            AppSettings.Global.PubKey    = pubKey;

            if (privKeyChanged)
            {
                AppSettings.Global.PrivKey = privKey;
            }

            ShowToast("Settings Saved");
        }