public static ServerSettings GetServerFromSettings(string name) { var server = new ServerSettings(); var xmlDoc = new XmlDocument(); xmlDoc.Load(fileName); foreach (XmlNode expression in xmlDoc.SelectNodes(expressionXPath)) { if (name == expression.Attributes["name"].Value) { using (var smc = new SymCryptography()) { server.Domain = expression.Attributes["domain"].Value; server.IP = expression.Attributes["ip"].Value; server.IsHttp = expression.Attributes["isHttp"].Value.BoolParse(); server.Name = expression.Attributes["name"].Value; server.Password = smc.Decrypt(expression.Attributes["password"].Value); server.Path = expression.Attributes["path"].Value; server.RootDirectory = expression.Attributes["rootDirectory"].Value; server.Username = expression.Attributes["username"].Value; break; } } } return(server); }
public void EncryptAndDecryptTest() { string plainText = "hello,my name is jsjs-gchao"; SymCryptography crypt = new SymCryptography(); string cryptedText = crypt.Encrypt(plainText); string decryptedText = crypt.Decrypt(cryptedText); Assert.AreEqual(plainText, decryptedText, decryptedText); }
static void Main(string[] args) { string plainText = "hello,my name is jsjs-gchao"; SymCryptography crypt = new SymCryptography(); string cryptedText = crypt.Encrypt(plainText); string decryptedText = crypt.Decrypt(cryptedText); Console.WriteLine(string.Format("PlainText:{0}", plainText)); Console.WriteLine(string.Format("cryptedText:{0}", cryptedText)); Console.ReadKey(); }