Salut,
Apparement il faut respecter le typage sinon les valeur de retour ne sont pas les mêmes:
SELECT HASHBYTES ('MD5', 'MAVALEUR')
Donne
0xDC1950D98C3EB60C0C89DAEDAB3C8DAD
1 2 3 4 5
|
DECLARE @HashThis nvarchar(max);
SELECT @HashThis = CONVERT(nvarchar,'MAVALEUR');
SELECT HashBytes('MD5', @HashThis);
GO |
Donne
0xA2CCAAAD39FF5C90447162FE1C54D9D8
cf. http://msdn.microsoft.com/fr-fr/libr...5(SQL.90).aspx
Est-ce que qqn sait quelle syntaxe il faut utiliser pour obtenir le même resultat qu'avec l'encodage MD5 du framework?
-----------------------------
Bon ben après un petit test avec ce code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public static string Md5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
} |
Tools.Md5Hash("MAVALEUR").ToUpperInvariant()
Donne
DC1950D98C3EB60C0C89DAEDAB3C8DAD
Arf mince, je suis pas dans le forum .Net C#. Mille excuses. Je le laisse tt de même.
A+
Partager