I am trying to convert a 128 bit binary to a unique identifier in SQL that is similar to Net and Java is. / P>
I know that Java uses big endians, so I want to make that base.
I can get a gap in the right nant, but in reality I am struggling with it in SQL Server.
Java:
byte [] bytesformase = "google.com" .getBytes ("UTF-8"); MessageDigest MD = MessageDigest.getInstance ("MD5"); Byte [] md5 = md.digest (bytesfomes); Bytebuffer BB = Bitebuffer. Wet (MD5); Longbuffer ig = BB Longbuffer (); Come back to the new UUID (ig.get (0), ig.get (1)); 1d5920f4-b44b-27a8-02bd-77c4f0536f5a returns
. Net
System.Security.Cryptography.MD5 c = System.Security.Cryptography.MD5.Create (); Byte [] B = C. Compute hash (encoding.utf.getbites ("google.com")); Int z = System.Net.IPAddress.HostToNetworkOrder (BitConverter.ToInt32 (B, 0)); Less y = System.Net.IPAddress.HostToNetworkOrder (Bitcoin.ToInt16 (B, 4)); Small x = System.Net.IPAddress.HostToNetworkOrder (Bitcutone to.Int16 (b, 6)); Guid G = New Guid (z, y, x, b.Skip (8) .oir ()); Greetings; 1d5920f4-b44b-27a8-02bd-77c4f0536f5a returns
sql
DECLARE @s VARCHAR (MAX) = 'google COM '-' goolge.com 'DECLARE @ MD5 Binari (16) = Hashbites (' MD5 ', @s) DECLARE @ one binary (4) = convert (binary (4), reverse (convert (binary (4) , LEFT (@ MD5, 4)) DECLARE @ B Binari (2) = Convert (Binari (2), Reverse (Convert (Binari (2), Wright (@ MD5, 12)) DECLARE @ C Binary ( 2) = Convert (Binari (2), Reverse (converter (Binari (2), Wright (@ MD5, 10)) DECLARE @ D Binari (8) = Convert (Binari (8), Wright (@ MD5, 8)) convert Vert (UNIQUEIDENTIFIER, @ A + B + @ C + @ D) Returns D86B5A7F-7A25-4895-A6D0-63BA3A706627
I can do all three To create the same value, we convert to an int64, but the GUID is bothering me.
If you correct the spelling of google in your SQL instance (this is goolge in your post), you get the correct result.
No comments:
Post a Comment