string valu = (string)dataGridView1.Rows[2].Cells[8].Value; dataGridView1.Rows[2].Cells[8].Value = UnprotectPassword(valu); dataGridView1.Refresh();
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System.Security.Cryptography; (Ajouter aussi la référence : System.Security au projet) static string ProtectPassword(string clearPassword) { byte[] bytes = Encoding.UTF8.GetBytes(clearPassword); byte[] protectedBytes = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser); return Convert.ToBase64String(protectedBytes); } static string UnprotectPassword(string protectedPassword) { byte[] protectedBytes = Convert.FromBase64String(protectedPassword); byte[] bytes = ProtectedData.Unprotect(protectedBytes, null, DataProtectionScope.CurrentUser); return Encoding.UTF8.GetString(bytes); } // donc on a une chaine string sChaine = "bidule"; //La je la crypt via la fonction ProtectPassword() string sChaine_Cryp = ProtectPassword(sChaine); //Cela me renvoi le mot de passe sous cette forme ci : // AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA39Y1R1+Cu0yn7aXIYMUtDQAAAAAC // Et pour decrypter on utilise UnprotectPassword() sChaine = UnprotectPassword(sChaine_Cryp); //Ceci me renvoi "bidule"
string valu = (string)dataGridView1.Rows[2].Cells[8].Value; dataGridView1.Rows[2].Cells[8].Value = UnprotectPassword(valu); dataGridView1.Refresh();