在SQL Server中使用HashBytes从DB返回不同的结果 [英] Using HashBytes in SQL Server returns different results from DB

查看:95
本文介绍了在SQL Server中使用HashBytes从DB返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用两种不同的方式运行:

  SELECT HASHBYTES('md5',ZLA_PASSWORD),ZLA_PASSWORD,len(ZLA_PASSWORD)FROM ZLA_PASSWORD; 

SELECT HASHBYTES('md5','123456');

我得到两个不同的结果,只有第二个是有效的:

  0xCE0BFD15059B68D67688884D7A3D3E8C 123456 6 
0xE10ADC3949BA59ABBE56E057F20F883E


$ b b

这是在SQL Server 2005上完成的。



检查123456上的MD5的结果与在线检查的第二个结果相同。



任何想法?



谢谢!

解决方案

您有不同的数据类型

  declare @ str1 as varchar(10)
declare @ str2 as nvarchar(10)

set @ str1 ='123456'
set @ str2 ='123456'

select
hashbytes('md5',@ str1)as'varchar',
hashbytes('md5',@ str2)as'nvarchar'


$ b

结果

  varchar nvarchar 
0xE10ADC3949BA59ABBE56E057F20F883E 0xCE0BFD15059B68D67688884D7A3D3E8C


I try to calculate md5 hash on a certain value, but I get a weird result.

I run it in two different ways:

SELECT HASHBYTES('md5',ZLA_PASSWORD),ZLA_PASSWORD, len(ZLA_PASSWORD) FROM ZLA_PASSWORD;

SELECT HASHBYTES('md5', '123456');

I get two different results, where only the second one is valid:

0xCE0BFD15059B68D67688884D7A3D3E8C  123456  6
0xE10ADC3949BA59ABBE56E057F20F883E

This is done on an SQL Server 2005.

checking the result of MD5 on 123456 was the same as the second result checking online.

Any ideas?

Thanks!

解决方案

You have different data types

declare @str1 as varchar(10)
declare @str2 as nvarchar(10)

set @str1 = '123456'
set @str2 = '123456'

select
  hashbytes('md5', @str1) as 'varchar',
  hashbytes('md5', @str2) as 'nvarchar'

Result

varchar                             nvarchar
0xE10ADC3949BA59ABBE56E057F20F883E  0xCE0BFD15059B68D67688884D7A3D3E8C

这篇关于在SQL Server中使用HashBytes从DB返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆