我正在尝试创建一个通用散列算法,将字符串散列为 64 位整数。
我能够正确地散列字符串:sql:
select
convert
(
varchar(64),
HASHBYTES
(
'SHA1',
'google.com'
),
2
)
返回BAEA954B95731C68AE6E45BD1E252EB4560CDC45
C#
System.Security.Cryptography.SHA1 c = System.Security.Cryptography.SHA1.Create();
System.Text.StringBuilder sb = new StringBuilder();
byte[] b = c.ComputeHash(Encoding.UTF8.GetBytes("google.com"));
for (int i = 0; i < b.Length;i++ )
{
byte by = b[i];
sb.Append(by.ToString("x2").ToUpper());
}
return sb.ToString();
重新运行BAEA954B95731C68AE6E45BD1E252EB4560CDC45
但是,当我转换为 bigint/long 时,值不匹配: sql:
select
convert
(
bigint,
HASHBYTES
(
'SHA1',
'google.com'
)
)
返回2172193747348806725
C#:
System.Security.Cryptography.SHA1 c = System.Security.Cryptography.SHA1.Create();
byte[] b = c.ComputeHash(Encoding.UTF8.GetBytes("google.com"));
return BitConverter.ToInt64(b, 0);
返回7501998164347841210
关于如何让这些数字匹配的任何想法?