Bonjour

J'ai besoin d'écrire en dur dans mon code un mot de passe or j'ai toujours gardé en tête que le code généré par C# était facile à décompiler et que cette pratique etait hautement déconseilliée

en cherchant des solutions je suis tombé sur protectedData https://msdn.microsoft.com/fr-fr/lib...ecteddata.aspx

qui semble s'utiliser super simplement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System.Security.Cryptography;
 
...
 
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);
}
Mais j'ai bien du mal à comprendre ce que ça fait et si oui ou non ça sécurise quelque chose...
Si cryptage il y a la clé se trouve où ?
Le mot de passe est protégé comment avec ça ?

merci