alexandernst / yii2-scrypt
为 Yii2 的 Scrypt 密钥派生函数
0.0.4
2015-04-04 15:17 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-14 18:04:05 UTC
README
为 Yii2 的 Scrypt 密钥派生函数
要使用它,只需在您的 composer.json 文件中要求此扩展
"alexandernst/yii2-scrypt": "0.0.4",
然后将它添加到 Yii2 的组件配置中
'components' => [ 'Scrypt' => [ 'class' => 'alexandernst\Scrypt\Scrypt' ], ]
要派生一个密钥,请使用以下方法
/** * Scrypt algorithm * * @param string $password * @param string $salt * @param int $n CPU/Memory cost parameter, must be larger than 1, a power of 2 and less than 2^(128 * r / 8) * @param int $r Block size * @param int $p Parallelization parameter, a positive integer less than or equal to ((2^32-1) * hLen) / MFLen where hLen is 32 and MFlen is 128 * r * @param int $length Length of the output key * @throws Exception * @return string */ echo bin2hex(\Yii::$app->Scrypt->calc("plain password", "salt", 8, 8, 16, 32));
此类通过所有在文档中指定的测试。