Partage [Tuto] Crypter / Décrypter un texte en C# codgage c++(sprx)

  • Auteur de la discussion BRAKO IH|T
  • Date de début
B

BRAKO IH|T

Visiteur
Visiteur
#1

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;
Puis ce code n'importe ou :
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:
textBox2.Text = ProtectPassword(textBox1.Text);
textBox1.Text = "";
Et dans le bouton décrypter :
Code:
textBox1.Text = UnprotectPassword(textBox2.Text);
textBox2.Text = "";
résultat

 

ƓŦΛ_ƤAƝƊA™

∇ Insσmηi'Hλck™∇
Supяêmε
26/8/15
450
399
1843
32
www.societyfrenchmodding.net
#7
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;
Puis ce code n'importe ou :
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:
textBox2.Text = ProtectPassword(textBox1.Text);
textBox1.Text = "";
Et dans le bouton décrypter :
Code:
textBox1.Text = UnprotectPassword(textBox2.Text);
textBox2.Text = "";

résultat

Merci du partage je vais essayer