alexandernst/yii2-scrypt

为 Yii2 的 Scrypt 密钥派生函数

安装次数: 77

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

公开问题: 0

类型:yii2-extension

0.0.4 2015-04-04 15:17 UTC

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));

此类通过所有在文档中指定的测试。