1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
uploaderfilesigner.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\UserField\File;
4
5
6use Bitrix\Main\Security\Sign\Signer;
7use Bitrix\Main\Security\Sign\BadSignatureException;
8
10{
11 private const SALT_PREFIX = 'UploaderFileSigner_';
12 public function __construct(
13 private readonly string $entityId,
14 private readonly string $fieldName
15 )
16 {
17 }
18
19 public function sign(int $fileId): string
20 {
21 return (new Signer())->sign((string)$fileId, $this->getSalt());
22 }
23
24 public function verify(string $signedString, int $fileId): bool
25 {
26 try
27 {
28 $unsignedFileId = (int)(new Signer())->unsign($signedString, $this->getSalt());
29
30 return ($fileId === $unsignedFileId);
31 }
32 catch (BadSignatureException $e)
33 {
34 return false;
35 }
36
37 return false;
38 }
39
40 private function getSalt(): string
41 {
42 return substr(preg_replace('/[^a-zA-Z0-9_.-]+/i', '',self::SALT_PREFIX . '_' . $this->entityId .'_' . $this->fieldName), 0, 50);
43 }
44}
__construct(private readonly string $entityId, private readonly string $fieldName)
Определения uploaderfilesigner.php:12
verify(string $signedString, int $fileId)
Определения uploaderfilesigner.php:24
$entityId
Определения payment.php:4