mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
downhash
This commit is contained in:
@@ -50,7 +50,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ use Illuminate\Support\Str;
|
||||
|
||||
class ToolRepository extends BaseRepository
|
||||
{
|
||||
private static $encrypter;
|
||||
|
||||
public function backupWeb(): array
|
||||
{
|
||||
$webRoot = base_path();
|
||||
@@ -146,17 +144,8 @@ class ToolRepository extends BaseRepository
|
||||
return $backupResult;
|
||||
}
|
||||
|
||||
public function getEncrypter(): Encrypter
|
||||
public function getEncrypter(string $key): Encrypter
|
||||
{
|
||||
if (!is_null(self::$encrypter)) {
|
||||
return self::$encrypter;
|
||||
}
|
||||
$key = nexus_env('APP_KEY');
|
||||
$prefix = 'base64:';
|
||||
if (Str::startsWith($key,$prefix)) {
|
||||
$key = substr($key, strlen($prefix));
|
||||
$key = base64_decode($key);
|
||||
}
|
||||
return self::$encrypter = new Encrypter($key, 'AES-256-CBC');
|
||||
return new Encrypter($key, 'AES-256-CBC');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,15 +254,20 @@ class TorrentRepository extends BaseRepository
|
||||
return "$speed/s";
|
||||
}
|
||||
|
||||
public function encryptDownHash($id, $uid): string
|
||||
public function encryptDownHash($id, $user): string
|
||||
{
|
||||
if (!is_array($user) || empty($user['passkey']) || empty($user['id'])) {
|
||||
$user = User::query()->findOrFail(intval($user), ['id', 'passkey'])->toArray();
|
||||
}
|
||||
//down hash is relative to user passkey
|
||||
$key = md5($user['passkey'] . date('Ymd') . $user['id']);
|
||||
$toolRep = new ToolRepository();
|
||||
$payload = [
|
||||
'id' => $id,
|
||||
'uid' => $uid,
|
||||
'uid' => $user['id'],
|
||||
'date' => date('Ymd'),
|
||||
];
|
||||
return $toolRep->getEncrypter()->encrypt($payload);
|
||||
return $toolRep->getEncrypter($key)->encrypt($payload);
|
||||
}
|
||||
|
||||
public function decryptDownHash($downHash)
|
||||
|
||||
Reference in New Issue
Block a user