简体   繁体   English

在MySQL中存储SHA-512哈希

[英]Storing SHA-512 Hashes in MySQL

I was wondering if I use PHP's hash() function to generate sha512 hashes how would my MySQL table field look like in-order to be capable of holding the hashed password. 我想知道我是否使用PHP的hash()函数生成sha512哈希我的MySQL表字段如何才能保存哈希密码。

Here is my current MySQL password field layout 这是我当前的MySQL密码字段布局

char(40)

A sha512 hash is represented as a 128 characters-long string . sha512哈希表示为128个字符长的字符串

For example, the following portion of code : 例如,以下代码部分:

$sha512 = hash('sha512', "Hello, World!");
echo strlen($sha512);

Will give this output : 会给出这个输出:

128


Which means your char(40) is far too small, and that you should use a char(128) . 这意味着你的char(40)太小了,你应该使用char(128)


Another solution would be to store it in a binary form, and not a string -- which would mean 64 bytes. 另一种解决方案是将其存储为二进制形式,而不是字符串 - 这意味着64字节。

But note it might be harder to deal with that representation, in some cases, I suppose. 但请注意,在某些情况下,我认为处理这种表示可能更难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM