Ceci est une question juste théorique. Je suis à un point de départ pour programmer une énorme vue réseau multi-serveurs / multi-clients. P>
question: strong> Quelqu'un peut-il me fournir juste une liste de noms de méthodes! p>
Quelles sont les méthodes possibles de cryptage irréversible em> ou aka cryptage à sens unique em>? Et quels sont les plus appropriés pour être mis en œuvre dans mon cas et dans .net? P>
4 Réponses :
Vous voulez essentiellement utiliser MD5 ou SHA-256. Oh, et fyi, si c'est une façon, ça s'appelle un hash em>. La documentation MSDN couvre à la fois des haubans de manière approfondie. P>
byte[] data = new byte[DATA_SIZE]; byte[] result; SHA256 shaM = new SHA256Managed(); result = shaM.ComputeHash(data); Here is the overview and here is the namespace with standard features. Simply look at HashAlgorithm and its descendants.
Seulement 8 minutes , D Vous êtes ma réponse. De toute façon merci
Ouais j'attendais juste 10 minutes pour appliquer votre réponse comme parfaite: D
Comme cela n'a été mentionné par d'autres, MD5 et SHA sont des algorithmes de hachage qui peuvent être utilisés pour cela. Une chose qui doit être prise en compte avant de choisir un cependant, est-ce importante qu'il s'agit de «déchiffrer» (les hachages ne peuvent pas être déchiffrés au sens normal du mot). MD5 et SHA sont conçus pour être rapides, ce qui signifie que créer des tables arc-en-ciel ( http://en.wikipedia.org / wiki / rainbow_tables ) avec beaucoup de hashes sera aussi rapide. Avec la vitesse des GPUS modernes, des centaines de millions de millions de hachages peuvent être générées chaque seconde, ce qui signifie qu'il est possible de brute force MD5 et SHA assez rapidement. P>
Si vous stockez des choses comme un mot de passe, il est préférable d'utiliser un algorithme de hachage conçu pour être lent, comme Bcrypt ( http://bcrypt.codeplex.com/ ) p>
Pour tout nouveaux visiteurs à cette question, crackstation.net a une implémentation complète .NET au fond , ainsi que d'une explication assez détaillée de ce que vous devez faire et comment tous les travaux
Le code suivant est copié sans modifications de crackstation.net p>
/* * Password Hashing With PBKDF2 (http://crackstation.net/hashing-security.htm). * Copyright (c) 2013, Taylor Hornby * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Text; using System.Security.Cryptography; namespace PasswordHash { /// <summary> /// Salted password hashing with PBKDF2-SHA1. /// Author: havoc AT defuse.ca /// www: http://crackstation.net/hashing-security.htm /// Compatibility: .NET 3.0 and later. /// </summary> public class PasswordHash { // The following constants may be changed without breaking existing hashes. public const int SALT_BYTE_SIZE = 24; public const int HASH_BYTE_SIZE = 24; public const int PBKDF2_ITERATIONS = 1000; public const int ITERATION_INDEX = 0; public const int SALT_INDEX = 1; public const int PBKDF2_INDEX = 2; /// <summary> /// Creates a salted PBKDF2 hash of the password. /// </summary> /// <param name="password">The password to hash.</param> /// <returns>The hash of the password.</returns> public static string CreateHash(string password) { // Generate a random salt RNGCryptoServiceProvider csprng = new RNGCryptoServiceProvider(); byte[] salt = new byte[SALT_BYTE_SIZE]; csprng.GetBytes(salt); // Hash the password and encode the parameters byte[] hash = PBKDF2(password, salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE); return PBKDF2_ITERATIONS + ":" + Convert.ToBase64String(salt) + ":" + Convert.ToBase64String(hash); } /// <summary> /// Validates a password given a hash of the correct one. /// </summary> /// <param name="password">The password to check.</param> /// <param name="correctHash">A hash of the correct password.</param> /// <returns>True if the password is correct. False otherwise.</returns> public static bool ValidatePassword(string password, string correctHash) { // Extract the parameters from the hash char[] delimiter = { ':' }; string[] split = correctHash.Split(delimiter); int iterations = Int32.Parse(split[ITERATION_INDEX]); byte[] salt = Convert.FromBase64String(split[SALT_INDEX]); byte[] hash = Convert.FromBase64String(split[PBKDF2_INDEX]); byte[] testHash = PBKDF2(password, salt, iterations, hash.Length); return SlowEquals(hash, testHash); } /// <summary> /// Compares two byte arrays in length-constant time. This comparison /// method is used so that password hashes cannot be extracted from /// on-line systems using a timing attack and then attacked off-line. /// </summary> /// <param name="a">The first byte array.</param> /// <param name="b">The second byte array.</param> /// <returns>True if both byte arrays are equal. False otherwise.</returns> private static bool SlowEquals(byte[] a, byte[] b) { uint diff = (uint)a.Length ^ (uint)b.Length; for (int i = 0; i < a.Length && i < b.Length; i++) diff |= (uint)(a[i] ^ b[i]); return diff == 0; } /// <summary> /// Computes the PBKDF2-SHA1 hash of a password. /// </summary> /// <param name="password">The password to hash.</param> /// <param name="salt">The salt.</param> /// <param name="iterations">The PBKDF2 iteration count.</param> /// <param name="outputBytes">The length of the hash to generate, in bytes.</param> /// <returns>A hash of the password.</returns> private static byte[] PBKDF2(string password, byte[] salt, int iterations, int outputBytes) { Rfc2898DeriveBytes pbkdf2 = new Rfc2898DeriveBytes(password, salt); pbkdf2.IterationCount = iterations; return pbkdf2.GetBytes(outputBytes); } } }
Pourquoi est-il nécessaire d'utiliser un comparateur de temps constant lors de la comparaison des hachages qui sont essentiellement des tableaux d'octets aléatoires?
MD5 ou SHA256? Y a-t-il vraiment autre chose à dire?
Si le cryptage était irréversible, quel serait le point? (Faire la distinction entre algorithmes de hachage ...)
Il suffit de besoin d'une liste pas une comparaison !!