private OtpAuthData readData(bool skipType = false) { if (OtpAuthUtils.checkUriString(textBoxKey.Text)) { OtpAuthData data = OtpAuthUtils.uriToOtpAuthData(new Uri(textBoxKey.Text)); if (this.data != null) { data.loadedFields = this.data.loadedFields; } return(data); } else { OtpAuthData data = new OtpAuthData(); if (this.data != null) { data = (OtpAuthData)this.data.Clone(); } string secret = textBoxKey.Text.Replace(" ", string.Empty).Replace("-", string.Empty); if (string.IsNullOrEmpty(this.textBoxKey.Text)) { throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationMissingSecret); } if (checkBoxCustomSettings.Checked) { if (this.radioButtonBase32.Checked) { data.Encoding = OtpSecretEncoding.Base32; } else if (this.radioButtonBase64.Checked) { data.Encoding = OtpSecretEncoding.Base64; } else if (this.radioButtonHex.Checked) { data.Encoding = OtpSecretEncoding.Hex; } else if (this.radioButtonUtf8.Checked) { data.Encoding = OtpSecretEncoding.UTF8; } } // Secret validation, will throw an error if invalid secret = OtpAuthUtils.correctPlainSecret(secret, data.Encoding); OtpAuthUtils.validatePlainSecret(secret, data.Encoding); if (checkBoxCustomSettings.Checked) { if (!skipType) { data.Type = comboBoxTypeIndexValue[comboBoxType.SelectedIndex]; } if (data.Type == OtpType.Totp || data.Type == OtpType.Steam) { int period = 30; if (int.TryParse(this.textBoxPeriodCounter.Text, out period)) { if (period <= 0) { throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger); } } else { throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger); } data.Period = period; } else if (data.Type == OtpType.Hotp) { int counter = 0; if (int.TryParse(this.textBoxPeriodCounter.Text, out counter)) { if (counter < 0) { throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger); } } else { throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger); } data.Counter = counter; } data.Digits = comboBoxLengthIndexValue[comboBoxLength.SelectedIndex]; if (this.radioButtonSha1.Checked) { data.Algorithm = OtpHashMode.Sha1; } else if (this.radioButtonSha256.Checked) { data.Algorithm = OtpHashMode.Sha256; } else if (this.radioButtonSha512.Checked) { data.Algorithm = OtpHashMode.Sha512; } data.KeeOtp1Mode = checkboxOldKeeOtp.Checked; } data.SetPlainSecret(secret); return(data); } }