/// <summary> /// Saves keys /// </summary> private void OnSaveCommand() { // check app sid length if (this.AppSidText.Length != 36) { DialogManager.ShowErrorDialog("Incorrect APP SID length! APP SID should be 36 symbols length."); return; } // check app key length if (this.AppKeyText.Length != 32) { DialogManager.ShowErrorDialog("Incorrect APP KEY length! APP KEY should be 32 symbols length."); return; } // update keys to provide new values CoreApi.UpdateKeys(this.AppKeyText, this.AppSidText); // encrypt keys and save in settings byte[] encryptedAppKey = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppKeyText)); byte[] encryptedAppSid = SecurityUtility.Encrypt(Encoding.UTF8.GetBytes(this.AppSidText)); UserSettingsUtility.SaveCredentials(encryptedAppKey, encryptedAppSid); this.view.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="MainViewModel"/> class. /// </summary> public MainViewModel() { BusyIndicatorManager.EnabledChanged += this.BusyChanged; this.tabViewModels = new ObservableCollection <TabViewModel>(); this.CanDrop = true; this.StartPanelVisibility = Visibility.Visible; this.RecentFiles = new ObservableCollection <string>(UserSettingsUtility.LoadRecentFiles()); this.InitCommands(); }
/// <summary> /// Initializes static members of the <see cref="CoreApi"/> class. /// </summary> static CoreApi() { // try loading keys from settings byte[] appKey = UserSettingsUtility.LoadAppKey(); byte[] appSid = UserSettingsUtility.LoadAppSid(); // if any keys loaded, decrypt them if (appKey != null && appSid != null) { AppSid = Encoding.UTF8.GetString(SecurityUtility.Decrpyt(appSid)); AppKey = Encoding.UTF8.GetString(SecurityUtility.Decrpyt(appKey)); } }
/// <summary> /// Initializes a new instance of the <see cref="CredentialsViewModel"/> class /// </summary> public CredentialsViewModel() { // init commands this.SaveCommand = new RelayCommand(x => this.OnSaveCommand()); this.CancelCommand = new RelayCommand(x => this.OnCancelCommand()); // init view this.view = new CredentialsView(this); // try loading keys byte[] appKey = UserSettingsUtility.LoadAppKey(); byte[] appSid = UserSettingsUtility.LoadAppSid(); // decrypt loaded keys if any if (appKey != null && appSid != null) { this.AppSidText = Encoding.UTF8.GetString(SecurityUtility.Decrpyt(appSid)); this.AppKeyText = Encoding.UTF8.GetString(SecurityUtility.Decrpyt(appKey)); } // display view this.view.ShowDialog(); }