首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在php中为CRYPT_BLOWFISH函数设置blowfish

如何在php中为CRYPT_BLOWFISH函数设置blowfish
EN

Stack Overflow用户
提问于 2014-03-18 17:04:23
回答 1查看 103关注 0票数 0

我使用这个代码加密我的数据到blwofish,但我不知道真的转换为河豚或其他加密。

echo crypt('ab','$2a$09$anexamplestringforsalt$')."\n

";和我正在尝试底层代码,但它是假的echo CRYPT_BLOWFISH('ab','$2a$09$anexamplestringforsalt$')."\n

";

EN

回答 1

Stack Overflow用户

发布于 2014-03-19 22:42:30

它是crypt参数字符串,用于定义所使用的算法:

代码语言:javascript
复制
$2a : This describes the algorithm (BCrypt) but should be 2y nowadays
$09 : This is the number of rounds and is usually 10 or higher
$anexamplestringforsalt : This should be a really random salt of a given alphabet

要生成PHP哈希,使用新的password_hash()函数要安全得多,不过,对于早期的BCrypt版本也有一个compatibility pack

代码语言:javascript
复制
// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($password, PASSWORD_BCRYPT);

// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22474588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档