如何生成用于散列的随机长盐? [英] How to generate a random, long salt for use in hashing?
问题描述
PHP用什么方法制作用于散列的随机可变长度的盐?假设我想制作16个字符的长盐-我该怎么做?
edit:mcrypt扩展名已被弃用.
对于新项目,请查看
random_bytes(int $ length)
和钠(自php 7.2核心开始)扩展. /p>
如果 mcrypt扩展可用,您可以简单地使用 What is a way in PHP to make a random, variable length salt for use in hashing? Let's say I want to make a 16-character long salt - how would I do it? edit: the mcrypt extension has been deprecated.
For new projects take a look at If the mcrypt extension is available you could simply use mcrypt_create_iv(size, source) to create a salt. Since each byte of the "string" can be in the range between 0-255 you need a binary-safe function to save/retrieve it. 这篇关于如何生成用于散列的随机长盐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
random_bytes ( int $length )
and the sodium (as of php 7.2 core-)extension.
$iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
var_dump($iv);