public void EncryptedPassword() { string key = ConfigurationManager.AppSettings["EncryptionKey"]; string password = "******"; string encryptedPassword = EncrytpDecrypt.Encrypt(password, key); Console.WriteLine("encryptedPassword is " + encryptedPassword); }
public void DecryptPassword() { string key = ConfigurationManager.AppSettings["EncryptionKey"]; string password = ConfigurationManager.AppSettings["Password"]; string decryptedPassword = EncrytpDecrypt.Decrypt(password, key); Console.WriteLine("decryptedPassword is " + decryptedPassword); }
/// <summary> /// Read from config.xml file. /// It's for supporing Jenkins integration /// </summary> public static void InitializeForJenkins() { string configFile = @"C:\Workspace\bhp-or-vdt-seleniumtests\VDT.SeleniumTests\VDT.Tests\config.xml"; string environment = ""; string devBaseUrl = ""; string devDbConnectString = ""; string testBaseUrl = ""; string testDbConnectString = ""; string encryptedPassword = ""; string encryptionKey = ""; using (XmlReader reader = XmlReader.Create(configFile) ) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "BrowserType": if (reader.Read()) { BrowserType = reader.Value; } break; case "BrowserDriverPath": if (reader.Read()) { BrowserDriverPath = reader.Value; } break; case "TestEnvironment": if (reader.Read()) { environment = reader.Value; } break; case "DevBaseUrl": if (reader.Read()) { devBaseUrl = reader.Value; } break; case "DevDbConnectString": if (reader.Read()) { devDbConnectString = reader.Value; } break; case "TestBaseUrl": if (reader.Read()) { testBaseUrl = reader.Value; } break; case "TestDbConnectString": if (reader.Read()) { testDbConnectString = reader.Value; } break; case "UserName": if (reader.Read()) { UserName = reader.Value; } break; case "EncryptedPassword": if (reader.Read()) { encryptedPassword = reader.Value; } break; case "EncryptionKey": if (reader.Read()) { encryptionKey = reader.Value; } break; } } } } if (environment.Equals("Dev", StringComparison.InvariantCultureIgnoreCase)) { BaseUrl = devBaseUrl; DbConnectionString = devDbConnectString; } else if (environment.Equals("Test", StringComparison.InvariantCultureIgnoreCase)) { BaseUrl = testBaseUrl; DbConnectionString = testDbConnectString; } else { throw new ArgumentException(); } Password = EncrytpDecrypt.Decrypt(encryptedPassword, encryptionKey); BaseUrl = $"https://{UserName}:{Password}@{BaseUrl}"; }