Example #1
0
        public void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            Username = reader.GetAttribute(ATTR.username) ?? string.Empty;
            string encryptedPassword = reader.GetAttribute(ATTR.password_encrypted);

            if (encryptedPassword != null)
            {
                try
                {
                    Password = TextUtil.DecryptString(encryptedPassword);
                }
                catch (Exception)
                {
                    Password = string.Empty;
                }
            }
            else
            {
                Password = reader.GetAttribute(ATTR.password) ?? string.Empty;
            }

            ServerUrl = reader.GetAttribute(ATTR.server_url);
            // Consume tag
            reader.Read();
            Validate();
        }
Example #2
0
        protected override void ReadXElement(XElement xElement)
        {
            base.ReadXElement(xElement);
            IdentityServer = (string)xElement.Attribute(ATTR.identity_server.ToString());
            ClientScope    = (string)xElement.Attribute(ATTR.client_scope.ToString());
            string clientSecret = (string)xElement.Attribute(ATTR.client_secret.ToString());

            if (clientSecret != null)
            {
                ClientSecret = TextUtil.DecryptString(clientSecret);
            }
        }
Example #3
0
        public void TestDecryptGarbage()
        {
            const string garbageString = "garbage";

            AssertEx.ThrowsException <FormatException>(delegate
            {
                TextUtil.DecryptString(garbageString);
            });
            AssertEx.ThrowsException <CryptographicException>(delegate
            {
                TextUtil.DecryptString(Convert.ToBase64String(Encoding.UTF8.GetBytes(garbageString)));
            });
            Assert.AreEqual(garbageString, TextUtil.DecryptString(TextUtil.EncryptString(garbageString)));
        }
Example #4
0
        public void TestEncryptString()
        {
            const string testString1 = "TestString1";
            const string testString2 = "TestString2";
            string       encrypted1  = TextUtil.EncryptString(testString1);

            byte[] bytes1 = Convert.FromBase64String(encrypted1);
            CollectionAssert.AreNotEqual(bytes1, Encoding.UTF8.GetBytes(testString1));

            string decrypted1 = TextUtil.DecryptString(encrypted1);

            Assert.AreEqual(testString1, decrypted1);

            string encrypted2 = TextUtil.EncryptString(testString2);

            Assert.AreNotEqual(encrypted1, encrypted2);
        }
Example #5
0
        protected virtual void ReadXElement(XElement xElement)
        {
            Username = (string)xElement.Attribute(ATTR.username.ToString()) ?? string.Empty;
            string encryptedPassword = (string)xElement.Attribute(ATTR.password.ToString());

            if (encryptedPassword != null)
            {
                try
                {
                    Password = TextUtil.DecryptString(encryptedPassword);
                }
                catch (Exception)
                {
                    Password = string.Empty;
                }
            }

            ServerUrl = (string)xElement.Attribute(ATTR.server_url.ToString());
        }
Example #6
0
        public void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            Username = reader.GetAttribute(ATTR.username) ?? string.Empty;
            string encryptedPassword = reader.GetAttribute(ATTR.password_encrypted);

            if (encryptedPassword != null)
            {
                try
                {
                    Password = TextUtil.DecryptString(encryptedPassword);
                }
                catch (Exception)
                {
                    Password = string.Empty;
                }
            }
            else
            {
                Password = reader.GetAttribute(ATTR.password) ?? string.Empty;
            }
            string uriText = reader.GetAttribute(ATTR.uri);

            if (string.IsNullOrEmpty(uriText))
            {
                throw new InvalidDataException(Resources.Server_ReadXml_A_Panorama_server_must_be_specified);
            }
            try
            {
                URI = new Uri(uriText);
            }
            catch (UriFormatException)
            {
                throw new InvalidDataException(Resources.Server_ReadXml_Server_URL_is_corrupt);
            }
            // Consume tag
            reader.Read();

            Validate();
        }