wtframework / security
What the Framework?! 安全
v0.1.0
2023-12-28 14:02 UTC
Requires
- php: ^8.2
- wtframework/config: ^0.1
Requires (Dev)
- pestphp/pest: ^2.29
README
安装
composer require wtframework/security
文档
配置
使用 Config 库来设置安全配置设置。
use WTFramework\Config\Config; Config::set([ 'security' => [ 'encryption_key' => 'ec5964323dc239ab63417a0f98ff1eef', // openssl rand -hex 16 'hash_salt' => 'f93101e3a5f4f09f8c1a9ac0f9301c6e', // openssl rand -hex 16 'password_pepper' => '2429fc585eef890c13e2c5307dcb02f23d8d83ea86740d864a6e79e2a7613cd1a95efd42', // openssl rand -hex 36 ], ]);
设置
security
根安全设置。
security.password_pepper
应用于每个密码的全局盐。
security.password_algorithm
密码散列算法。默认为 PASSWORD_DEFAULT。
security.password_options
密码散列选项。默认为 ['cost' => 12]。
security.encryption_key
openssl_encrypt 密码。
security.encryption_algorithm
openssl_encrypt 加密方法。默认为 aes-128-gcm。
security.encryption_options
openssl_encrypt 选项。默认为 0。
security.hash_salt
hash_pbkdf2 盐。
security.hash_algorithm
hash_pbkdf2 散列算法。默认为 sha3-512。
security.hash_iterations
hash_pbkdf2 迭代次数。默认为 10000。
WTFramework\Security\Password
散列密码
use WTFramework\Security\Password; $hash = Password::hash('password');
验证散列密码
if (Password::verify('password', $hash)) { // ... }
检查密码是否需要重新散列
if (Password::needsRehash($hash)) { // ... }
WTFramework\Security\Crypt
加密文本
use WTFramework\Security\Crypt; $encrypted = Crypt::encrypt('text');
解密文本
$text = Crypt::decrypt($encrypted);
散列文本
$hashed = Crypt::hash('text');
生成版本 4 UUID
$uuid = Crypt::uuid();