Hey !
Aujourd'hui on se retrouve pour un tuto !
Requis :
- Visual Studio
Tutoriel :
Tout d'abord, créer un nouveau projet !
Ensuite partie design, personnellement j'ai fais sa :
J'ai pris 2 TextBox et 2 Boutons !
Partie, codage.
Allez dans Projet -> Ajouter une référence... -> Assemblys -> Framework -> System.Security
Puis cochez System.Security et ajouter la référence.
Ensuite ajoutez ce code en haut :
Puis ce code n'importe ou :
Aujourd'hui on se retrouve pour un tuto !
Requis :
- Visual Studio
Tutoriel :
Tout d'abord, créer un nouveau projet !
Ensuite partie design, personnellement j'ai fais sa :

J'ai pris 2 TextBox et 2 Boutons !
Partie, codage.
Allez dans Projet -> Ajouter une référence... -> Assemblys -> Framework -> System.Security
Puis cochez System.Security et ajouter la référence.
Ensuite ajoutez ce code en haut :
Code:
using System.Security.Cryptography;
Code:
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);
}
Ensuite dans le bouton crypter entrez ceci :
Code:
Code:
Code:
textBox2.Text = ProtectPassword(textBox1.Text);
textBox1.Text = "";
Et dans le bouton décrypter :
Code:
textBox1.Text = UnprotectPassword(textBox2.Text);
textBox2.Text = "";
Résultat :

Dernière édition: