public void CorrectlyConvertsUtf8BytesToSecureString() { byte[] candidate = Encoding.UTF8.GetBytes("lazy 🐢🖐🏿 doc."); SecureString result = SecureStringExtensions.BytesToSecureString(candidate, Encoding.UTF8); Assert.IsNotNull(result); Assert.AreEqual("lazy 🐢🖐🏿 doc.", SecureStringExtensions.SecureStringToString(result)); candidate = null; result = SecureStringExtensions.BytesToSecureString(candidate, Encoding.UTF8); Assert.IsNull(result); }
/// <summary> /// Converts the XML document which contains a version 2 config, to a version 3 config. /// </summary> /// <param name="root">Root node of the XML document.</param> protected virtual void UpdateSettingsFrom2To3(XElement root) { XElement cloudStorageAcount = root.Element("cloud_storage_account"); if (cloudStorageAcount != null) { XElement cloudStorageCredentialsElement = new XElement("cloud_storage_credentials"); XElement cloudTypeElement = cloudStorageAcount.Element("cloud_type"); if (cloudTypeElement != null) { cloudStorageCredentialsElement.Add(new XElement("cloud_storage_id", cloudTypeElement.Value.ToLowerInvariant())); } XElement userElement = cloudStorageAcount.Element("username"); if (userElement != null) { cloudStorageCredentialsElement.Add(new XElement("username", EncryptProperty(userElement.Value))); } XElement passwordElement = cloudStorageAcount.Element("protected_password"); if (passwordElement != null) { byte[] passwordBytes = _dataProtectionService.Unprotect(passwordElement.Value); SecureString password = SecureStringExtensions.BytesToSecureString(passwordBytes, Encoding.Unicode); cloudStorageCredentialsElement.Add(new XElement("password", EncryptProperty(password.SecureStringToString()))); } XElement urlElement = cloudStorageAcount.Element("url"); if (urlElement != null) { cloudStorageCredentialsElement.Add(new XElement("url", urlElement.Value)); } XElement accessTokenElement = cloudStorageAcount.Element("oauth_access_token"); if (accessTokenElement != null) { cloudStorageCredentialsElement.Add(new XElement("access_token", EncryptProperty(accessTokenElement.Value))); } root.AddFirst(cloudStorageCredentialsElement); } }