Silverlight – Hash SHA1 dans vos applications

Par Fabien Lavocat Le 26. novembre 2009 à 16:40

Silverlight

Aujourd’hui, j’ai été confronté à un problème de sécurité dans une application Silverlight que je réalise (vous en verrez un peu plus prochainement). J’utilise de l’authentification pour des utilisateurs, or pour hacher des mots de passe, il n’y a pas de méthode managée toute prête qui prend en paramètre une chaine de caractère et qui ressort le hash SHA1. Nous allons donc créer une méthode d’extention. Commencer par importer les espaces de noms suivants :

using System.Security.Cryptography;
using System.Text;

Ensuite, dans une classe statique, nous créons la méthode suivante :

public static String ToSHA1(this String entry)
{
   
SHA1Managed sHA1Managed = new SHA1Managed();
   
Byte[] result = sHA1Managed.ComputeHash(new UTF8Encoding().GetBytes(entry));
   
StringBuilder hashedString = new StringBuilder();
   
foreach (Byte outputByte in result)
        hashedString.Append(outputByte.ToString(
"x2").ToUpper());

   
return hashedString.ToString();
}

Nous pouvons donc maintenant l’utiliser de cette façon :

String password = "password";
String hashedPassword = password.ToSHA1();

Tags :

Silverlight

Commentaires

03/12/2009 17:51:46 #

Nk54

Et hop ! Dans mes favoris rubrique Silverlight/Sécurité Smile

Merci à toi.

Nk54 France

05/12/2009 17:45:02 #

fabien lavocat

Merci Smile

fabien lavocat France

Ajouter un commentaire


(Affichera votre icône Gravatar)

  Country flag

biuquote
  • Commentaire
  • Aperçu immédiat
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen - Updated by Fabien Lavocat

A propos de l'auteur

Fabien Lavocat Lavocat Fabien
Ingénieur Multimédia - TMM Communication

"Blog-Microsoft.fr is an independent blog and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft Corporation."

Contactez-moi Send mail

Calendar

<<  mars 2010  >>
lumamejevesadi
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Publicité