SQL-Server验证SHA2_512哈希过程

时间:2015-06-11 08:18:43

标签: sql-server tsql encryption cryptography sha512

考虑这个方法

declare @pswd nvarchar(max);
set @pswd = '2YKRCqHv';

Select 
    orig = a.Hash,
    hashA = 0x0200 + a.Salt + Hashbytes('SHA2_512', cast('2YKRCqHv' as varbinary(max)) + a.Salt),
    hashB = 0x0200 + a.Salt + Hashbytes('SHA2_512', cast(@pswd as varbinary(max)) + a.Salt)
from DB a

where 
a.Hash = 
0x0200 + a.Salt+ Hashbytes('SHA2_512', cast('2YKRCqHv' as varbinary(max)) + a.Salt)
or
a.Hash = 
0x0200 + a.Salt+ Hashbytes('SHA2_512', cast(@pswd as varbinary(max)) + a.Salt)

输出:

orig    0x0200BB316075603286E929221B9C04411AEC602A98B295CC05FCFFA809C2B553A100F4EBD4AA6FB3458E0B7C7E6D6B36FEA4908DF0AECA5142A26FA06B30F125253E15D585EE
hashA   0x0200BB316075603286E929221B9C04411AEC602A98B295CC05FCFFA809C2B553A100F4EBD4AA6FB3458E0B7C7E6D6B36FEA4908DF0AECA5142A26FA06B30F125253E15D585EE
hashB   0x0200BB316075C91147A2AEC396358C3F950C7E930B8DF0F9AC05628E00A74663502EE7BFCE68AA7BA3EC8303AE65107C72CAEF95111DD85CE45F210291B2800141CA37863A09

为什么A和B不同?我该如何创建验证密码程序?

1 个答案:

答案 0 :(得分:1)

这是因为hashA CAST VARCHAR VARBINARY hashB CAST NVARCHAR VARBINARY declare @pswd nvarchar(max); set @pswd = '2YKRCqHv'; Select orig = a.Hash, hashA = 0x0200 + a.Salt + Hashbytes('SHA2_512', cast(N'2YKRCqHv' as varbinary(max)) + a.Salt), hashB = 0x0200 + a.Salt + Hashbytes('SHA2_512', cast(@pswd as varbinary(max)) + a.Salt) from DB a where a.Hash = 0x0200 + a.Salt+ Hashbytes('SHA2_512', cast(N'2YKRCqHv' as varbinary(max)) + a.Salt) or a.Hash = 0x0200 + a.Salt+ Hashbytes('SHA2_512', cast(@pswd as varbinary(max)) + a.Salt) N HashA@pswd

第一个是非Unicode,因此不同。

尝试:

VARCHAR

请注意在orig的密码前添加temp = split("A BUYS: PRODUCT @ 85 / B SELLS"," ") A = temp(0) Product = temp(2) qty = temp(4) B = temp(6) ,这会导致它成为Unicode,然后生成相同的结果。

或者,更改.Photos > a > #HoverImg:last-child声明以使用.index-page .Photos a img,其产生与function HeightCalc(x, n) { $(x).each(function() { var Calc = ($(this).height() + 50) / 2; // Calculate height of images $(this).siblings(n).css({ "bottom": Calc }); // Move divs according to calc. total }); } HeightCalc(".index-page .Photos a img", ".HoverImg"); 相同的输出。