SHA256哈希多长时间? [英] How long is the SHA256 hash?
问题描述
我将使用密码+ salt运行SHA256
,但是我不知道在设置MySQL数据库时将VARCHAR
设置多长时间.好的长度是多少?
I'm going to run SHA256
on a password + salt, but I don't know how long to make my VARCHAR
when setting up the MySQL database. What is a good length?
推荐答案
sha256的长度为256位-顾名思义.
A sha256 is 256 bits long -- as its name indicates.
由于sha256返回一个十六进制表示,所以4个位足以编码每个字符(而不是8个,如ASCII),因此256个位将表示64个十六进制字符,因此您需要一个varchar(64)
甚至一个
Since sha256 returns a hexadecimal representation, 4 bits are enough to encode each character (instead of 8, like for ASCII), so 256 bits would represent 64 hex characters, therefore you need a varchar(64)
, or even a char(64)
, as the length is always the same, not varying at all.
演示:
$hash = hash('sha256', 'hello, world!');
var_dump($hash);
会给您:
$ php temp.php
string(64) "68e656b251e67e8358bef8483ab0d51c6619f3e7a1a9f0e75838d41ff368f728"
即一个包含64个字符的字符串.
i.e. a string with 64 characters.
这篇关于SHA256哈希多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!