SHA256哈希多长时间? [英] How long is the SHA256 hash?

查看:772
本文介绍了SHA256哈希多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用密码+ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆