2011-08-02 3 views
0

Il est utilisé pour crypter une chaîne pour créer une empreinte unique comme 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648.Créer un cryptage unique

Comment puis-je le convertir de la 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648 à la chaîne? MD5 est un chiffrement unique, il faut donc utiliser tripleDES pour le récupérer. mais la façon de créer une chaîne comme ce 8FAC-5806-FF54-4174-F89E-43DE-97A6-5648 selon la méthode ci-dessous:

public static string Encrypt(string strToEncrypt, string strKey) 
    { 
     try 
     { 
      TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider(); 
      MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider(); 

      byte[] byteHash, byteBuff; 
      string strTempKey = strKey; 

      byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey)); 
      objHashMD5 = null; 
      objDESCrypto.Key = byteHash; 
      objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB 

      byteBuff = ASCIIEncoding.ASCII.GetBytes(strToEncrypt); 
      return Convert.ToBase64String(objDESCrypto.CreateEncryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length)); 
     } 
     catch (Exception ex) 
     { 
      return "Wrong Input. " + ex.Message; 
     } 
    } 

Répondre

5

Le code utilise MD5 pour générer l'empreinte digitale. MD5 est un algorithme de hachage unidirectionnel. Cela signifie qu'il n'est pas possible d'inverser l'algorithme pour récupérer la valeur d'origine. Le hachage n'est pas un cryptage. Si vous voulez chiffrer votre chaîne et être capable de la déchiffrer, vous devez utiliser un algorithme de chiffrement tel que AES.

Questions connexes