/// <summary> /// Méthode appelée au chargement de la fenètre /// </summary> private void Connexion_Load(object sender, EventArgs e) { //deserialisation des parametres de la connection Serializer load = new Serializer(); param_connect = load.DeserialiserConnectBDD(); //TODO passer par la couche business if (param_connect != null) { textBox1.Text = param_connect.Username; textBox2.Text = param_connect.Password; } }
public void SerialiserConnectBDD(string username, string password) { SaveConnection save = new SaveConnection(username, password); TripleDESCryptoServiceProvider sa = new TripleDESCryptoServiceProvider(); save.IV = Convert.ToBase64String(sa.IV); save.Key = Convert.ToBase64String(sa.Key); save.Username = username; ICryptoTransform ct; MemoryStream ms; CryptoStream cs; byte[] byt; ct = sa.CreateEncryptor(sa.Key, sa.IV); byt = Encoding.UTF8.GetBytes(password); ms = new MemoryStream(); cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); save.Password = Convert.ToBase64String(ms.ToArray()); XmlSerializer serializer = new XmlSerializer(typeof(SaveConnection)); TextWriter writer = new StreamWriter("Connection_serialisation.xml"); serializer.Serialize(writer, save); writer.Close(); }