Sql Server 2005: what data type to use to store passwords hashed by SHA-256 algorithm?

六月ゝ 毕业季﹏ 提交于 2019-12-22 03:14:03

问题


In Sql Server 2005 what data type should be used to store passwords hashed by SHA-256 algorithm?

The data is hashed by the application and passed to the database


回答1:


I prefer to convert the hash-Code to an Hex-String in this case a varchar(64) will do the trick or an varchar (66) if you like a "0x"-prefix. In this way it is much easier to compare manually or (re)set values you have to copy/paste from other places. e.g you lost your admin-PW and want to reset it via SQL...




回答2:


The "Hash" attribute of the SHA256Managed class is an array of bytes, and HashSize is 256 bits, so I believe a binary(32) would be the simplest.

You could probably also put it into a varchar field using the ToBase64Transform. I'm not completely familiar with the Base64 Algorithm, but It seems like you would need probably need at least 43 characters to represent a 256 bit number in base 64. IIRC Base64 uses a couple padding characters, so I'd probably put it at varchar(50) just to be safe.




回答3:


varbinary(32) or binary (32).




回答4:


Should produce a 32-byte value (256 bits), so binary(32) ought to work.




回答5:


SHA-256 has a 256 bit output

256bits = 32 Bytes

So try varbinary(32)



来源:https://stackoverflow.com/questions/252156/sql-server-2005-what-data-type-to-use-to-store-passwords-hashed-by-sha-256-algo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!