When SQL Server attempts to do a MD5 hash on this string it most encode the
string to binary before hashing it. Does anyone know how varchar is encoded
,
i.e. what encoding is used for varchar? UTF-8? UTF-16? Example code:
SELECT HashBytes('MD5',CONVERT(varchar,’some string’))
If you send a nvarchar, it uses UTF-16, example:
SELECT HashBytes('MD5',CONVERT(nvarchar,’some
string’))
Thanks in advance. With this information I can write some C# code to create
a hash that matches what SQL server does.
-WayneWayne Berry (WayneBerry@.discussions.microsoft.com) writes:
> When SQL Server attempts to do a MD5 hash on this string it most encode
> the string to binary before hashing it. Does anyone know how varchar is
> encoded, i.e. what encoding is used for varchar? UTF-8? UTF-16?
> Example code:
> SELECT HashBytes('MD5',CONVERT(varchar,some string))
> If you send a nvarchar, it uses UTF-16, example:
> SELECT HashBytes('MD5',CONVERT(nvarchar,some string))
> Thanks in advance. With this information I can write some C# code to
> create a hash that matches what SQL server does.
I would suspect that it simply hashes the byte value. Which for varchar
means codes in the range 0 to 255(*), and for nvarchar a UTF-16 encoding.
(*) For Western scripts. For East Asian scripts it would be a double-
byte character set.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
Showing posts with label attempts. Show all posts
Showing posts with label attempts. Show all posts
Wednesday, March 7, 2012
Subscribe to:
Posts (Atom)