hashbytes returns int 的不同值?
hashbytes returns different values for int?
运行 SQL 服务器上的以下内容得到了 0xE864ECE8888043B67277C8B2CEFE96AD315FCCA4
。
select hashbytes('SHA1', cast(10 as varbinary(max)));
在 Sybase 上以下 SQLs return 0xEB408DDC4FA484E6BEFDF5954E56A2198C7A9FAB
select hashbytes('SHA1', cast(10 as varbinary(8000))), hashbytes('SHA1', 10 )
为什么 SHA1 在不同的数据库上得到不同的值?
MSSQL 和 Sybase 运行ning 在 cpu 上可能存在问题,字节顺序不同。
考虑以下 运行 针对 linux 上的 Sybase ASE 运行ning(我在 Solaris/x86 上对 Sybase ASE 也得到相同的结果):
select hashbytes('SHA1', cast(10 as varbinary(8000)) ),hashbytes('sha1',10 )
select hashbytes('SHA1', cast(10 as varbinary(8000)),using lsb),hashbytes('sha1',10,using lsb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using msb),hashbytes('sha1',10,using msb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using unicode_lsb),hashbytes('sha1',10,using unicode_lsb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using unicode_msb),hashbytes('sha1',10,using unicode_msb)
go
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xe864ece8888043b67277c8b2cefe96ad315fcca4
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xe864ece8888043b67277c8b2cefe96ad315fcca4
如您所见,我得到了您提到的两个值; %CCA4 匹配来自 运行ning hashbytes using msb 或 using unicode_msb.
你的 Sybase 版本是多少?
select @@version
运行 SQL 服务器上的以下内容得到了 0xE864ECE8888043B67277C8B2CEFE96AD315FCCA4
。
select hashbytes('SHA1', cast(10 as varbinary(max)));
在 Sybase 上以下 SQLs return 0xEB408DDC4FA484E6BEFDF5954E56A2198C7A9FAB
select hashbytes('SHA1', cast(10 as varbinary(8000))), hashbytes('SHA1', 10 )
为什么 SHA1 在不同的数据库上得到不同的值?
MSSQL 和 Sybase 运行ning 在 cpu 上可能存在问题,字节顺序不同。
考虑以下 运行 针对 linux 上的 Sybase ASE 运行ning(我在 Solaris/x86 上对 Sybase ASE 也得到相同的结果):
select hashbytes('SHA1', cast(10 as varbinary(8000)) ),hashbytes('sha1',10 )
select hashbytes('SHA1', cast(10 as varbinary(8000)),using lsb),hashbytes('sha1',10,using lsb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using msb),hashbytes('sha1',10,using msb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using unicode_lsb),hashbytes('sha1',10,using unicode_lsb)
select hashbytes('SHA1', cast(10 as varbinary(8000)),using unicode_msb),hashbytes('sha1',10,using unicode_msb)
go
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xe864ece8888043b67277c8b2cefe96ad315fcca4
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab
------------------------------------------ ------------------------------------------
0xeb408ddc4fa484e6befdf5954e56a2198c7a9fab 0xe864ece8888043b67277c8b2cefe96ad315fcca4
如您所见,我得到了您提到的两个值; %CCA4 匹配来自 运行ning hashbytes using msb 或 using unicode_msb.
你的 Sybase 版本是多少?
select @@version