feat: admin login
This commit is contained in:
57
app/Lib/Crypto/CryptoFactory.php
Normal file
57
app/Lib/Crypto/CryptoFactory.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Lib\Crypto;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 加密工厂
|
||||
*/
|
||||
class CryptoFactory
|
||||
{
|
||||
/**
|
||||
* 加密类主体
|
||||
* @var CryptoInterface
|
||||
*/
|
||||
protected CryptoInterface $cryptoInterface;
|
||||
|
||||
/**
|
||||
* 加密工厂
|
||||
* @param string $type
|
||||
* @param string $dataStr
|
||||
* @param string $key
|
||||
* @return ApiCrypto|CryptoInterface|JwtCrypto
|
||||
* @throws Exception
|
||||
*/
|
||||
public function cryptoClass(string $type, string $dataStr, string $key = ''): JwtCrypto|CryptoInterface|ApiCrypto
|
||||
{
|
||||
switch ($type) {
|
||||
case 'api':
|
||||
$apiCrypto = new ApiCrypto();
|
||||
$this->cryptoInterface = $apiCrypto;
|
||||
break;
|
||||
case 'jwt':
|
||||
$jwtCrypto = new JwtCrypto();
|
||||
$this->cryptoInterface = $jwtCrypto;
|
||||
break;
|
||||
case 'admin-password':
|
||||
$adminCrypto = new AdminPasswordCrypto();
|
||||
$this->cryptoInterface = $adminCrypto;
|
||||
$this->cryptoInterface->salt = $key;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('The encryption algorithm does not exist');
|
||||
}
|
||||
|
||||
$this->cryptoInterface->data = $dataStr;
|
||||
return $this->cryptoInterface;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user