[Tuto] Crypter / Décrypter un texte en C#

Statut
N'est pas ouverte pour d'autres réponses.

Akuw

Membre
Inscription
20 Janvier 2015
Messages
141
Réactions
53
Points
146
RGCoins
25
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 :
kEiqeEY.png

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 :
7468c9de3de257404a92e90ecbab1176.gif
 
Dernière édition:
Je vois pas pourquoi tu te mets en crédits car c'est une fonction dispo ici :

 
T'aurais pu faire une fonction de crypt/hash toi meme
 
Statut
N'est pas ouverte pour d'autres réponses.
Retour
Haut