java 如何创建mysql“sha-256”列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11921780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a mysql "sha-256" column?
提问by Daemonthread
For a password column, is there a mysql feature to store password hashed with "sha-256"? Or should I hash it from java code (like How to hash some string with sha256 in Java?) before I store it in database and then hash the password input every time and compare with the database column value to authenticate?
对于密码列,是否有 mysql 功能来存储用“sha-256”散列的密码?或者我应该在我将它存储在数据库中之前从 Java 代码中散列它(比如How to hash some string with sha256 in Java?)然后将它存储在数据库中然后每次散列密码输入并与数据库列值进行比较以进行身份验证?
TIA.
TIA。
回答by Mark Byers
You can convert the value to hex and use a char(n) column with the appropriate length - 64 in this case. The conversion can be done in MySQL by using the sha2
function with hash_length
set to 256.
您可以将值转换为十六进制并使用具有适当长度的 char(n) 列 - 在这种情况下为 64。可以使用设置为 256的sha2
函数在 MySQL 中完成转换hash_length
。
But for security reasons you should not store passwords hashed using SHA-256.
但出于安全原因,您不应存储使用 SHA-256 散列的密码。
Related
有关的