mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
torrent downhash encrypt by hashids
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\Standard;
|
||||
use App\Models\Team;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Hashids\Hashids;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -255,25 +256,24 @@ class TorrentRepository extends BaseRepository
|
||||
}
|
||||
|
||||
public function encryptDownHash($id, $user): string
|
||||
{
|
||||
$key = $this->getEncryptDownHashKey($user);
|
||||
return (new Hashids($key))->encode($id);
|
||||
}
|
||||
|
||||
public function decryptDownHash($downHash, $user)
|
||||
{
|
||||
$key = $this->getEncryptDownHashKey($user);
|
||||
return (new Hashids($key))->decode($downHash);
|
||||
}
|
||||
|
||||
private function getEncryptDownHashKey($user)
|
||||
{
|
||||
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' => $user['id'],
|
||||
'date' => date('Ymd'),
|
||||
];
|
||||
return $toolRep->getEncrypter($key)->encrypt($payload);
|
||||
}
|
||||
|
||||
public function decryptDownHash($downHash)
|
||||
{
|
||||
$toolRep = new ToolRepository();
|
||||
return $toolRep->getEncrypter()->decrypt($downHash);
|
||||
return md5($user['passkey'] . date('Ymd') . $user['id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user