SHA2_256直接比较

问题描述 投票:0回答:2

我想找出给定的SHA 256哈希是否已经存储在数据库中。

create table #tmpH (input VARCHAR(20), hsh VARBINARY(8000))

insert into #tmpH values('Hello', HASHBYTES('SHA2_256', 'Hello'))
insert into #tmpH values('Internet', HASHBYTES('SHA2_256', 'Internet'))

input       hsh
Hello       0x185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969
Internet    0x57E8A431DEEC0D70DA0A26EA3392E59688B11B79EDFD04E9DA823B16BCD1D4D7

select * from #tmpH where hsh = '0x185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969'                            --Nope
select * from #tmpH where hsh = CAST('0x185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969' as varbinary(8000))   --Nope
select * from #tmpH where cast(hsh as VARCHAR(100)) = '0x185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969'      --Nope
select * from #tmpH where CONVERT(VARCHAR(100), hsh, 2) = '0x185F8DB32271FE25F561A6FC938B2E264306EC304EDA518007D1764826381969'  --Nope
select * from #tmpH where hsh = HASHBYTES('SHA2_256', 'Hello')          --Works

当我没有原始值并且无法自己对其进行哈希处理时,如何比较由同一算法生成的两个哈希?

我正在使用MS SQL Server 2016。

sql-server tsql hash
2个回答
0
投票

varchar


0
投票

您还没有尝试过最简单的方法(顺便说一句,正在工作):

© www.soinside.com 2019 - 2024. All rights reserved.