// Token: 0x06005174 RID: 20852 RVA: 0x0012D668 File Offset: 0x0012B868 private static AlternateServiceAccountCredential LoadFromRegistry(RegistryKey rootKey, string valueName, bool decryptPasswords) { string text = rootKey.GetValue(valueName) as string; if (text == null) { return(null); } DateTime dateTime; Match match; if (!DateTime.TryParseExact(valueName, "yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out dateTime) || !(match = AlternateServiceAccountCredential.regexRegValue.Match(text)).Success) { return(new AlternateServiceAccountCredential(valueName, new DataValidationException(new ObjectValidationError(DirectoryStrings.FailedToParseAlternateServiceAccountCredential, null, AlternateServiceAccountCredential.GetRegistryValueDisplayPath(rootKey.Name, valueName))))); } byte[] array; Exception ex; try { array = Convert.FromBase64String(match.Groups["password"].Value); ex = null; } catch (FormatException ex2) { ex = ex2; array = null; } SecureString secureString = null; if (decryptPasswords && array != null) { try { secureString = CapiNativeMethods.DPAPIDecryptDataToSecureString(array, (CapiNativeMethods.DPAPIFlags) 0U); secureString.MakeReadOnly(); } catch (CryptographicException innerException) { ex = new DataSourceOperationException(DirectoryStrings.FailedToReadAlternateServiceAccountConfigFromRegistry(AlternateServiceAccountCredential.GetRegistryValueDisplayPath(rootKey.Name, valueName)), innerException); } } return(new AlternateServiceAccountCredential(valueName, ex, false, dateTime.ToUniversalTime(), match.Groups["domain"].Value, match.Groups["userName"].Value, secureString)); }
// Token: 0x06005171 RID: 20849 RVA: 0x0012D5B4 File Offset: 0x0012B7B4 internal void SaveToRegistry(RegistryKey rootKey) { if (this.Password == null) { throw new InvalidOperationException("SaveToRegistry cannot be called on deserialized instances."); } base.CheckWritable(); if (rootKey.GetValue(this.registryValueName) != null) { throw new DataSourceTransientException(DirectoryStrings.FailedToWriteAlternateServiceAccountConfigToRegistry(AlternateServiceAccountCredential.GetRegistryValueDisplayPath(rootKey.Name, this.registryValueName))); } string value = string.Format("{0}\\{1}\\{2}", this.Domain, this.UserName, Convert.ToBase64String(CapiNativeMethods.DPAPIEncryptData(this.Password, (CapiNativeMethods.DPAPIFlags) 0U))); rootKey.SetValue(this.registryValueName, value); this.propertyBag.SetIsReadOnly(true); }